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()