summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2019-11-22 17:02:19 +0100
committerCristian Adam <cristian.adam@qt.io>2019-11-22 17:08:02 +0000
commit974536c4aae7766560a3251d82c3519fc78b3cd7 (patch)
tree2533b218131cfca8eca9e1e28b3ab266c667904c /cmake
parentf4efaf54d552d4ab4601119a6bc6d2991c82888d (diff)
CMake: Do feature testing for linker flags
Instead of hardcoding which platforms and which compilers support certain linker features, do the proper probing via check_cxx_source_compiles. Change-Id: I676010970d8f3a8f2a8340c5d15dfcef76fe9191 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuild.cmake19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index f51e84b19a..f4af4a76f6 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -760,17 +760,30 @@ macro(qt_parse_all_arguments result type flags options multiopts)
endif()
endmacro()
+include(CheckCXXSourceCompiles)
function(qt_internal_add_link_flags_no_undefined target)
if (NOT QT_BUILD_SHARED_LIBS)
return()
endif()
if (GCC OR CLANG)
- if(APPLE)
+ set(previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+
+ set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,-undefined,error")
+ check_cxx_source_compiles("int main() {}" HAVE_DASH_UNDEFINED_ERROR)
+ if(HAVE_DASH_UNDEFINED_ERROR)
set(no_undefined_flag "-Wl,-undefined,error")
- elseif(LINUX OR MINGW OR ANDROID)
+ endif()
+
+ set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--no-undefined")
+ check_cxx_source_compiles("int main() {}" HAVE_DASH_DASH_NO_UNDEFINED)
+ if(HAVE_DASH_DASH_NO_UNDEFINED)
set(no_undefined_flag "-Wl,--no-undefined")
- else()
+ endif()
+
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
+ if (NOT HAVE_DASH_UNDEFINED_ERROR AND NOT HAVE_DASH_DASH_NO_UNDEFINED)
message(FATAL_ERROR "Platform linker doesn't support erroring upon encountering undefined symbols. Target:\"${target}\".")
endif()
target_link_options("${target}" PRIVATE "${no_undefined_flag}")