From 161c2f95447399f24a412a1c4b2e05ba47d41eee Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 30 Jan 2024 16:30:16 +0100 Subject: [PATCH] Add the the implicit promotion to global for Qt platform targets Bundled 3rdparty libraries link Qt platform targets implicitly, which lead to the dependency resolution when the library is used by another targets. For qtbase this works just fine since all platform targets are not imported and they are used from a build tree. But in case if 3rdparty library is built as part of Qt repo different from qtbase platform targets are imported and trigger the global promotion in CMake. Usually qt_find_package for the 3rdparty libraries is called somewhere in src/... directory and since Qt::Platform* targets are already created in the top-level repo CMakeLists.txt by the find_package(Qt ...) call, this leads to an error. The propsed fix forces the global promotion of Qt platform targets as soon as they created by the one of the initial find_package(Qt ...) calls. Change-Id: Iceb53f9ecccbdc438f9bc3bcc836583cfd4de535 Reviewed-by: Alexandru Croitor Reviewed-by: Qt CI Bot --- cmake/QtBuildRepoHelpers.cmake | 1 + cmake/QtTargetHelpers.cmake | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index ef9cd137085..c2a8ee56bb1 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -11,6 +11,7 @@ macro(qt_internal_project_setup) # Check for the minimum CMake version. qt_internal_require_suitable_cmake_version() qt_internal_upgrade_cmake_policies() + qt_internal_promote_platform_targets_to_global() endmacro() macro(qt_build_internals_set_up_private_api) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 71ffde93c0f..9fec179c3cd 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -1582,3 +1582,32 @@ function(qt_internal_export_genex_properties) COMPONENT Devel ) endfunction() + +# The macro promotes the Qt platform targets and their dependencies to global. The macro shouldn't +# be called explicitly in regular cases. It's called right after the first find_package(Qt ...) +# call in the qt_internal_project_setup macro. +# This allows using the qt_find_package(Wrap<3rdparty> PROVIDED_TARGETS ...) function, +# without the risk of having duplicated global promotion of Qt internals. This is especially +# sensitive for the bundled 3rdparty libraries. +macro(qt_internal_promote_platform_targets_to_global) + if(TARGET Qt6::Platform) + get_target_property(is_imported Qt6::Platform IMPORTED) + if(is_imported) + set(known_platform_targets + Platform + PlatformCommonInternal + PlatformModuleInternal + PlatformPluginInternal + PlatformAppInternal + PlatformToolInternal + ) + set(versionless_platform_targets ${known_platform_targets}) + + list(TRANSFORM known_platform_targets PREPEND Qt6::) + list(TRANSFORM versionless_platform_targets PREPEND Qt::) + qt_find_package(Qt6 PROVIDED_TARGETS + ${known_platform_targets} + ${versionless_platform_targets}) + endif() + endif() +endmacro()