path: root/cmake/
diff options
authorAlexey Edelev <>2021-06-29 18:00:39 +0200
committerAlexey Edelev <>2021-07-02 15:17:06 +0200
commite80b0107952272aa3382a84aeb6d11b6047d775e (patch)
treeff9d69552133287129092298367eaf8d681e8660 /cmake/
parentc72b7b8e5e530fbd03b704380940f5fa86e5341d (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 <> Reviewed-by: Alexandru Croitor <>
Diffstat (limited to 'cmake/')
1 files changed, 4 insertions, 1 deletions
diff --git a/cmake/ b/cmake/
index cc3b2d7fce..92e47a04a0 100644
--- a/cmake/
+++ b/cmake/
@@ -126,4 +126,7 @@ if (_Qt_NOTFOUND_MESSAGE)
+ __qt_internal_check_link_order_matters()
+ __qt_internal_check_cmp0099_available()