Skip to content

Commit

Permalink
Add the the implicit promotion to global for Qt platform targets
Browse files Browse the repository at this point in the history
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 <alexandru.croitor@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
  • Loading branch information
semlanik committed Jan 31, 2024
1 parent 180afc7 commit 161c2f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/QtBuildRepoHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions cmake/QtTargetHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 161c2f9

Please sign in to comment.