From 13a4de6bf65d29a808ecd94b382ac0c1add9e0b3 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Wed, 16 Jun 2021 19:24:59 +0200 Subject: [PATCH] Remove target specific flags from the linker capabilities check Remove target specific flags from static_link_order. Move the check to the common config.tests folder. Amends 5fb99e3860eb43f4bacacec7f4a4626cb0159b14 Pick-to: 6.2 Task-number: QTBUG-93002 Task-number: QTBUG-94528 Change-Id: I1368075ec6bd1e743b2b89fd93143df38a278ec2 Reviewed-by: Alexandru Croitor --- cmake/QtBaseGlobalTargets.cmake | 4 +- .../QtBuildInternalsConfig.cmake | 2 +- cmake/QtConfig.cmake.in | 2 +- cmake/QtPublicTargetHelpers.cmake | 47 +++++++------------ .../static_link_order/CMakeLists.txt | 0 .../static_link_order/main.cpp | 0 .../static_link_order/objlib.cpp | 0 .../static_link_order/staticlib1.cpp | 0 .../static_link_order/staticlib2.cpp | 0 9 files changed, 20 insertions(+), 35 deletions(-) rename {cmake/config.tests => config.tests}/static_link_order/CMakeLists.txt (100%) rename {cmake/config.tests => config.tests}/static_link_order/main.cpp (100%) rename {cmake/config.tests => config.tests}/static_link_order/objlib.cpp (100%) rename {cmake/config.tests => config.tests}/static_link_order/staticlib1.cpp (100%) rename {cmake/config.tests => config.tests}/static_link_order/staticlib2.cpp (100%) diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 2d858d657f..37a024ed3c 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -240,8 +240,8 @@ qt_copy_or_install(FILES # Install public config.tests files. qt_copy_or_install(DIRECTORY - "cmake/config.tests" - DESTINATION "${__GlobalConfig_install_dir}" + "config.tests/static_link_order" + DESTINATION "${__GlobalConfig_install_dir}/config.tests" ) # Install public CMake files. diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index b4acfde3ac..2547282dca 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -962,7 +962,7 @@ function(qt_internal_static_link_order_test) # TODO: This check is added before the actual release of CMake 3.21. So need to check if the # target version meets the expectations. if(CMAKE_VERSION VERSION_LESS 3.21) - __qt_internal_check_link_order_matters(${QT_CMAKE_EXPORT_NAMESPACE}::Platform) + __qt_internal_check_link_order_matters(link_order_matters) if(link_order_matters) set(summary_message "no") else() diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 35cd3f77ca..8e080a7ea0 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -111,4 +111,4 @@ if (_Qt_NOTFOUND_MESSAGE) endif() __qt_internal_defer_promote_targets_in_dir_scope_to_global() -__qt_internal_check_link_order_matters(@INSTALL_CMAKE_NAMESPACE@::Platform) +__qt_internal_check_link_order_matters() diff --git a/cmake/QtPublicTargetHelpers.cmake b/cmake/QtPublicTargetHelpers.cmake index c5e9ce7b63..be76efd835 100644 --- a/cmake/QtPublicTargetHelpers.cmake +++ b/cmake/QtPublicTargetHelpers.cmake @@ -16,49 +16,30 @@ function(__qt_internal_strip_target_directory_scope_token target out_var) endfunction() # Tests if linker could resolve circular dependencies between object files and static libraries. -function(__qt_internal_static_link_order_public_test target result) +function(__qt_internal_static_link_order_public_test result) # We could trust iOS linker if(IOS) - set(QT_HAVE_LINK_ORDER_MATTERS_${target} "FALSE" CACHE BOOL "Link order matters") + set(QT_HAVE_LINK_ORDER_MATTERS "FALSE" CACHE BOOL "Link order matters") endif() - if(DEFINED QT_HAVE_LINK_ORDER_MATTERS_${target}) - set(${result} "${QT_HAVE_LINK_ORDER_MATTERS_${target}}" PARENT_SCOPE) + if(DEFINED QT_HAVE_LINK_ORDER_MATTERS) + set(${result} "${QT_HAVE_LINK_ORDER_MATTERS}" PARENT_SCOPE) return() endif() - set(link_options_property LINK_OPTIONS) - set(compile_definitions_property COMPILE_DEFINITIONS) - get_target_property(type ${target} TYPE) - if(type STREQUAL "INTERFACE_LIBRARY") - set(link_options_property INTERFACE_LINK_OPTIONS) - set(compile_definitions_property INTERFACE_COMPILE_DEFINITIONS) - endif() - - get_target_property(linker_options ${target} ${link_options_property}) - get_target_property(compile_definitions ${target} ${compile_definitions_property}) - set(linker_options "${CMAKE_EXE_LINKER_FLAGS} ${linker_options}") - set(compile_definitions "${CMAKE_CXX_FLAGS} ${compile_definitions}") - if(EXISTS "${QT_CMAKE_DIR}") - set(test_source_basedir "${QT_CMAKE_DIR}") + set(test_source_basedir "${QT_CMAKE_DIR}/..") else() set(test_source_basedir "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}") endif() - set(test_subdir "${target}") - string(TOLOWER "${test_subdir}" test_subdir) - string(MAKE_C_IDENTIFIER "${test_subdir}" test_subdir) try_compile(${result} - "${CMAKE_CURRENT_BINARY_DIR}/${test_subdir}/config.tests/static_link_order" + "${CMAKE_CURRENT_BINARY_DIR}/config.tests/static_link_order" "${test_source_basedir}/config.tests/static_link_order" static_link_order_test static_link_order_test - CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${linker_options}" - "-DCMAKE_CXX_FLAGS:STRING=${compile_definitions}" ) - message(STATUS "Check if linker can resolve circular dependencies for target ${target} \ -- ${${result}}") + message(STATUS "Check if linker can resolve circular dependencies - ${${result}}") # Invert the result if(${result}) @@ -67,7 +48,7 @@ function(__qt_internal_static_link_order_public_test target result) set(${result} TRUE) endif() - set(QT_HAVE_LINK_ORDER_MATTERS_${target} "${${result}}" CACHE BOOL "Link order matters") + set(QT_HAVE_LINK_ORDER_MATTERS "${${result}}" CACHE BOOL "Link order matters") set(${result} "${${result}}" PARENT_SCOPE) endfunction() @@ -92,14 +73,18 @@ function(__qt_internal_set_link_order_matters target link_order_matters) endfunction() # Function combines __qt_internal_static_link_order_public_test and -# __qt_internal_set_link_order_matters calls for the target. -function(__qt_internal_check_link_order_matters target) +# __qt_internal_set_link_order_matters calls on Qt::Platform target. +function(__qt_internal_check_link_order_matters) __qt_internal_static_link_order_public_test( - ${target} link_order_matters + link_order_matters ) __qt_internal_set_link_order_matters( - ${target} "${link_order_matters}" + ${QT_CMAKE_EXPORT_NAMESPACE}::Platform "${link_order_matters}" ) + + if("${ARGC}" GREATER "0" AND NOT ARGV0 STREQUAL "") + set(${ARGV0} ${link_order_matters} PARENT_SCOPE) + endif() endfunction() function(__qt_internal_process_dependency_resource_objects target) diff --git a/cmake/config.tests/static_link_order/CMakeLists.txt b/config.tests/static_link_order/CMakeLists.txt similarity index 100% rename from cmake/config.tests/static_link_order/CMakeLists.txt rename to config.tests/static_link_order/CMakeLists.txt diff --git a/cmake/config.tests/static_link_order/main.cpp b/config.tests/static_link_order/main.cpp similarity index 100% rename from cmake/config.tests/static_link_order/main.cpp rename to config.tests/static_link_order/main.cpp diff --git a/cmake/config.tests/static_link_order/objlib.cpp b/config.tests/static_link_order/objlib.cpp similarity index 100% rename from cmake/config.tests/static_link_order/objlib.cpp rename to config.tests/static_link_order/objlib.cpp diff --git a/cmake/config.tests/static_link_order/staticlib1.cpp b/config.tests/static_link_order/staticlib1.cpp similarity index 100% rename from cmake/config.tests/static_link_order/staticlib1.cpp rename to config.tests/static_link_order/staticlib1.cpp diff --git a/cmake/config.tests/static_link_order/staticlib2.cpp b/config.tests/static_link_order/staticlib2.cpp similarity index 100% rename from cmake/config.tests/static_link_order/staticlib2.cpp rename to config.tests/static_link_order/staticlib2.cpp