CMake: Export 3rdparty dependency find_package calls of private modules

Consider a Qt module with a 3rdparty library target in
PRIVATE_MODULE_INTERFACE, e.g. XKB::XKB in Qt6::GuiPrivate. Consumers of
GuiPrivate automatically depend on XKB::XKB. In order to do that they
must find_package(XKB ...). As all find_package calls for GuiPrivate are
in the same place as the ones for Gui, this package must be marked as
optional. Otherwise all consumers of Qt6::Gui would have to have the
xkbcommon package installed too.

This patch exports find_package calls for every 3rdparty public
dependency of private modules and marks them as optional.

Change-Id: Ia1eeb09c29927fb6634ef08b477684ed6f123267
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-09-24 12:02:44 +02:00
parent 1783b048fd
commit dae078e521

View File

@ -25,7 +25,7 @@ macro(qt_collect_third_party_deps target)
endif()
unset(_target_is_static)
foreach(dep ${${depends_var}})
foreach(dep ${${depends_var}} ${optional_public_depends})
# Gather third party packages that should be found when using the Qt module.
# Also handle nolink target dependencies.
string(REGEX REPLACE "_nolink$" "" base_dep "${dep}")
@ -44,6 +44,9 @@ macro(qt_collect_third_party_deps target)
if(dep_seen EQUAL -1 AND package_name)
list(APPEND third_party_deps_seen ${dep})
get_target_property(package_is_optional ${dep} INTERFACE_QT_PACKAGE_IS_OPTIONAL)
if(NOT package_is_optional AND dep IN_LIST optional_public_depends)
set(package_is_optional TRUE)
endif()
get_target_property(package_version ${dep} INTERFACE_QT_PACKAGE_VERSION)
if(NOT package_version)
set(package_version "")
@ -76,6 +79,11 @@ function(qt_internal_create_module_depends_file target)
get_target_property(public_depends "${target}" INTERFACE_LINK_LIBRARIES)
unset(optional_public_depends)
if(TARGET "${target}Private")
get_target_property(optional_public_depends "${target}Private" INTERFACE_LINK_LIBRARIES)
endif()
# Used for collecting Qt module dependencies that should be find_package()'d in
# ModuleDependencies.cmake.
get_target_property(target_deps "${target}" _qt_target_deps)
@ -227,6 +235,7 @@ function(qt_internal_create_plugin_depends_file target)
get_target_property(depends "${target}" LINK_LIBRARIES)
get_target_property(public_depends "${target}" INTERFACE_LINK_LIBRARIES)
get_target_property(target_deps "${target}" _qt_target_deps)
unset(optional_public_depends)
set(target_deps_seen "")
qt_collect_third_party_deps(${target})
@ -288,6 +297,8 @@ function(qt_internal_create_qt6_dependencies_file)
# This is the actual target we're querying.
set(actual_target Platform)
get_target_property(public_depends "${actual_target}" INTERFACE_LINK_LIBRARIES)
unset(depends)
unset(optional_public_depends)
# We need to collect third party deps that are set on the public Platform target,
# like Threads::Threads.