summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-12-16 18:51:31 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-20 10:39:11 +0000
commit37eefbacb81d26263f2f5602ac0cfd60b1e35e37 (patch)
treef3dc79af9cccc991563f6f4ec50748bea477a62c /cmake
parenta5e4e6e623c4e830d09ef12446dabeb6b988a322 (diff)
CMake: Fix detection of linker availability
Previously we passed flags like -ld-fuse=lld only to compile calls, but not to the link call of a compile test project. Make sure to pass it to the link call instead by using check_cxx_source_compiles + CMAKE_REQUIRED_LINK_OPTIONS instead of check_cxx_compiler_flag. Note the flag that is passed is still via passed via the compiler launcher and not directly to the linker. Remove duplicate flag handling code. Change-Id: I1bf90573904a9df83240b6debfee3cc9e425c6bb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit d6066d53fa70e1736ca64d468605a4a430644400) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtFeature.cmake40
-rw-r--r--cmake/QtInternalTargets.cmake10
-rw-r--r--cmake/QtProcessConfigureArgs.cmake2
3 files changed, 36 insertions, 16 deletions
diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake
index 09a1c8361c..3ade942f17 100644
--- a/cmake/QtFeature.cmake
+++ b/cmake/QtFeature.cmake
@@ -1118,6 +1118,33 @@ function(qt_config_compiler_supports_flag_test name)
set(TEST_${name} "${TEST_${name}}" CACHE INTERNAL "${label}")
endfunction()
+function(qt_internal_get_active_linker_flags out_var)
+ set(flags "")
+ if(GCC OR CLANG)
+ if(QT_FEATURE_use_gold_linker)
+ list(APPEND flags "-fuse-ld=gold")
+ elseif(QT_FEATURE_use_bfd_linker)
+ list(APPEND flags "-fuse-ld=bfd")
+ elseif(QT_FEATURE_use_lld_linker)
+ list(APPEND flags "-fuse-ld=lld")
+ endif()
+ endif()
+ set(${out_var} "${flags}" PARENT_SCOPE)
+endfunction()
+
+function(qt_internal_check_if_linker_is_available name)
+ if(DEFINED "TEST_${name}")
+ return()
+ endif()
+
+ cmake_parse_arguments(arg "" "LABEL;FLAG" "" ${ARGN})
+ set(flags "${arg_FLAG}")
+
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${flags})
+ check_cxx_source_compiles("int main() { return 0; }" TEST_${name})
+ set(TEST_${name} "${TEST_${name}}" CACHE INTERNAL "${label}")
+endfunction()
+
function(qt_config_linker_supports_flag_test name)
if(DEFINED "TEST_${name}")
return()
@@ -1126,15 +1153,10 @@ function(qt_config_linker_supports_flag_test name)
cmake_parse_arguments(arg "" "LABEL;FLAG" "" ${ARGN})
set(flags "-Wl,${arg_FLAG}")
- # Select the right linker.
- if(GCC OR CLANG)
- if(QT_FEATURE_use_gold_linker)
- list(PREPEND flags "-fuse-ld=gold")
- elseif(QT_FEATURE_use_bfd_linker)
- list(PREPEND flags "-fuse-ld=bfd")
- elseif(QT_FEATURE_use_lld_linker)
- list(PREPEND flags "-fuse-ld=lld")
- endif()
+ # Pass the linker that the main project uses to the compile test.
+ qt_internal_get_active_linker_flags(linker_flags)
+ if(linker_flags)
+ list(PREPEND flags ${linker_flags})
endif()
set(CMAKE_REQUIRED_LINK_OPTIONS ${flags})
diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake
index d8fa48f236..aef0c76abf 100644
--- a/cmake/QtInternalTargets.cmake
+++ b/cmake/QtInternalTargets.cmake
@@ -248,13 +248,11 @@ if(DEFINED QT_EXTRA_FRAMEWORKPATHS AND APPLE)
unset(__qt_fw_flags)
endif()
-if(QT_FEATURE_use_gold_linker)
- target_link_options(PlatformCommonInternal INTERFACE "-fuse-ld=gold")
-elseif(QT_FEATURE_use_bfd_linker)
- target_link_options(PlatformCommonInternal INTERFACE "-fuse-ld=bfd")
-elseif(QT_FEATURE_use_lld_linker)
- target_link_options(PlatformCommonInternal INTERFACE "-fuse-ld=lld")
+qt_internal_get_active_linker_flags(__qt_internal_active_linker_flags)
+if(__qt_internal_active_linker_flags)
+ target_link_options(PlatformCommonInternal INTERFACE "${__qt_internal_active_linker_flags}")
endif()
+unset(__qt_internal_active_linker_flags)
if(QT_FEATURE_enable_gdb_index)
target_link_options(PlatformCommonInternal INTERFACE "-Wl,--gdb-index")
diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake
index 6342df93bd..2440f63627 100644
--- a/cmake/QtProcessConfigureArgs.cmake
+++ b/cmake/QtProcessConfigureArgs.cmake
@@ -151,7 +151,7 @@ defstub(qt_find_package)
defstub(set_package_properties)
defstub(qt_qml_find_python)
defstub(qt_set01)
-
+defstub(qt_internal_check_if_linker_is_available)
####################################################################################################
# Define functions/macros that are called in qt_cmdline.cmake files