diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2021-06-29 18:00:39 +0200 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2021-07-02 15:17:06 +0200 |
commit | e80b0107952272aa3382a84aeb6d11b6047d775e (patch) | |
tree | ff9d69552133287129092298367eaf8d681e8660 /src/corelib/Qt6CoreMacros.cmake | |
parent | c72b7b8e5e530fbd03b704380940f5fa86e5341d (diff) |
Use target_link_options to propagate object libraries
target_link_options are placed by CMake at the beginning of a linker
line. This gives us an opportunity to use the function to propagate
object libraries. This change adds one more check in the root
Config.cmake file. If CMP0099 policy is enabled, CMake enables
propagating of the linking options when linking two static libraries
using the PRIVATE linking visibility, so we can rely on the correct
linking order and expect object libraries to be propagated.
Note that on the platforms where cmake version is higher than 3.16
Qt uses CMP0099 NEW in functions like qt_add_executable. This means
that at the moment of creating an executable target the TARGET_POLICY
genex will also be NEW, so we do not take into the account the user
defined CMP0099.
If the CMP0099 policy is not available for a certain CMake version
we skip the TARGET_POLICY check and simply disable propagation of
the object libraries using target_link_options for both user and Qt
libraries. This is applicable for the CMake versions 3.16 and less.
Linking approaches have the following priorities(from higher to lower)
after this change:
- target_link_libraries - works if link order matters not or CMake
version greater equal 3.21.
- target_link_options - works if CMP0099 is set to NEW by user or
if the CMake version is greater than or equal to 3.17 and an
executable is created using Qt functions.
- object library finalizer - works if CMake version is greater equal
3.19 or qt6_finalize_target is called explicitly.
- target_sources - is used when all the other approaches could not
be used.
Amends a1fd4f51ada82854f35654158a334454e760a9f7
Amends 3329212815777e33dfb4697b748d10927d73f44c
Pick-to: 6.2
Change-Id: I14f88caeb04e357191c840abeab89b03e210b796
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/corelib/Qt6CoreMacros.cmake')
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 81b98195ea..539c6bd159 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1472,6 +1472,17 @@ function(__qt_internal_propagate_object_library target object_library) "$<BOOL:${platform_link_order_property}>" ) + # Check if link options are propagated according to CMP0099 + # In user builds the _qt_cmp0099_policy_check is set to FALSE or $<TARGET_POLICY:CMP0099> + # depending on the used CMake version. + # See __qt_internal_check_cmp0099_available for details. + set(cmp0099_policy_check_property + "$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Platform,_qt_cmp0099_policy_check>" + ) + set(link_objects_using_link_options_condition + "$<BOOL:$<GENEX_EVAL:${cmp0099_policy_check_property}>>" + ) + # Use TARGET_NAME to have the correct namespaced name in the exports. set(objects "$<TARGET_OBJECTS:$<TARGET_NAME:${object_library}>>") @@ -1482,6 +1493,7 @@ function(__qt_internal_propagate_object_library target object_library) "${not_finalizer_mode_condition}," "${not_static_condition}," "${platform_link_order_condition}," + "$<NOT:${link_objects_using_link_options_condition}>," "${extra_conditions}" ">" ":${objects}>" @@ -1490,6 +1502,26 @@ function(__qt_internal_propagate_object_library target object_library) "${target_sources_genex}" ) + # Collect link conditions for the target_link_options call. + string(JOIN "" target_link_options_genex + "$<" + "$<AND:" + "${not_static_condition}," + "${platform_link_order_condition}," + "${link_objects_using_link_options_condition}," + "${extra_conditions}" + ">" + ":${objects}>" + ) + # target_link_options works well since CMake 3.17 which has policy CMP0099 set to NEW for the + # minimum required CMake version greated than or equal 3.17. The default is OLD. See + # https://cmake.org/cmake/help/git-master/policy/CMP0099.html for details. + # This provides yet another way of linking object libraries if user sets the policy to NEW + # before calling find_package(Qt...). + target_link_options(${target} INTERFACE + "${target_link_options_genex}" + ) + # Collect link conditions for the target_link_libraries call. string(JOIN "" target_link_libraries_genex "$<" |