diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-17 12:04:16 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-17 23:28:18 +0200 |
commit | b6c5e0667696c1d4abaf37f2224b2121b72cdebd (patch) | |
tree | 5bfb940603822e0f26529a056d24289bd155718c | |
parent | 7e335f290b1c3bc771097f01c715d1dc5f115077 (diff) |
CMake: Handle OPTIONAL_COMPONENTS in qt_find_package
The optional components arguments were not handled before which
caused the recorded package information for static builds to be
incorrect, it only recorded the package name without the component.
Remove REQUIRED_COMPONENTS TODO, there is no such find_package option,
it's already handled by the regular COMPONENTS code path.
Amends 07b6d3367debd8f15974abf0f5cdf48f0fe3a536
Pick-to: 6.1 6.2
Fixes: QTBUG-94501
Change-Id: Ib48a7befcb70e20c3f21315897d51d3064b48134
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | cmake/QtConfigDependencies.cmake.in | 8 | ||||
-rw-r--r-- | cmake/QtFindPackageHelpers.cmake | 14 | ||||
-rw-r--r-- | cmake/QtModuleDependencies.cmake.in | 5 | ||||
-rw-r--r-- | cmake/QtPluginDependencies.cmake.in | 5 | ||||
-rw-r--r-- | cmake/QtPostProcessHelpers.cmake | 8 |
5 files changed, 37 insertions, 3 deletions
diff --git a/cmake/QtConfigDependencies.cmake.in b/cmake/QtConfigDependencies.cmake.in index 52d6421b5e..159d3c020c 100644 --- a/cmake/QtConfigDependencies.cmake.in +++ b/cmake/QtConfigDependencies.cmake.in @@ -10,6 +10,7 @@ foreach(_target_dep ${_third_party_deps}) list(GET _target_dep 1 is_optional) list(GET _target_dep 2 version) list(GET _target_dep 3 components) + list(GET _target_dep 4 optional_components) set(find_package_args "${pkg}") if(version) list(APPEND find_package_args "${version}") @@ -18,6 +19,10 @@ foreach(_target_dep ${_third_party_deps}) string(REPLACE " " ";" components "${components}") list(APPEND find_package_args COMPONENTS ${components}) endif() + if(optional_components) + string(REPLACE " " ";" optional_components "${optional_components}") + list(APPEND find_package_args OPTIONAL_COMPONENTS ${optional_components}) + endif() # Already build an error message, because find_dependency calls return() on failure. set(__@INSTALL_CMAKE_NAMESPACE@_message "\nPackage: ${pkg}") @@ -27,6 +32,9 @@ foreach(_target_dep ${_third_party_deps}) if(components) string(APPEND __@INSTALL_CMAKE_NAMESPACE@_message "\nComponents: ${components}") endif() + if(optional_components) + string(APPEND __@INSTALL_CMAKE_NAMESPACE@_message "\nComponents: ${optional_components}") + endif() set(@INSTALL_CMAKE_NAMESPACE@_DEPENDENCY_NOT_FOUND_MESSAGE "${__@INSTALL_CMAKE_NAMESPACE@_message}") diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake index fca039549e..9f8ae1a9a9 100644 --- a/cmake/QtFindPackageHelpers.cmake +++ b/cmake/QtFindPackageHelpers.cmake @@ -18,7 +18,7 @@ macro(qt_find_package) set(find_package_options CONFIG NO_MODULE MODULE REQUIRED) set(options ${find_package_options} MARK_OPTIONAL) set(oneValueArgs MODULE_NAME QMAKE_LIB) - set(multiValueArgs PROVIDED_TARGETS COMPONENTS) + set(multiValueArgs PROVIDED_TARGETS COMPONENTS OPTIONAL_COMPONENTS) cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # If some Qt internal project calls qt_find_package(WrapFreeType), but WrapFreeType was already @@ -63,7 +63,10 @@ macro(qt_find_package) # Re-append components to forward them. list(APPEND arg_UNPARSED_ARGUMENTS "COMPONENTS;${arg_COMPONENTS}") endif() - # TODO: Handle REQUIRED_COMPONENTS. + if(arg_OPTIONAL_COMPONENTS) + # Re-append optional components to forward them. + list(APPEND arg_UNPARSED_ARGUMENTS "OPTIONAL_COMPONENTS;${arg_OPTIONAL_COMPONENTS}") + endif() # Don't look for packages in PATH if requested to. if(QT_NO_USE_FIND_PACKAGE_SYSTEM_ENVIRONMENT_PATH) @@ -154,6 +157,13 @@ macro(qt_find_package) PROPERTY INTERFACE_QT_PACKAGE_COMPONENTS ${components_as_string}) endif() + if(arg_OPTIONAL_COMPONENTS) + string(REPLACE ";" " " components_as_string "${arg_OPTIONAL_COMPONENTS}") + set_property(TARGET ${qt_find_package_target_name} + PROPERTY INTERFACE_QT_PACKAGE_OPTIONAL_COMPONENTS + ${components_as_string}) + endif() + get_property(is_global TARGET ${qt_find_package_target_name} PROPERTY IMPORTED_GLOBAL) qt_internal_should_not_promote_package_target_to_global( diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in index e9159a20d2..9729b24df2 100644 --- a/cmake/QtModuleDependencies.cmake.in +++ b/cmake/QtModuleDependencies.cmake.in @@ -22,6 +22,7 @@ foreach(_target_dep ${_third_party_deps}) list(GET _target_dep 1 is_optional) list(GET _target_dep 2 version) list(GET _target_dep 3 components) + list(GET _target_dep 4 optional_components) set(find_package_args "${pkg}") if(version) list(APPEND find_package_args "${version}") @@ -30,6 +31,10 @@ foreach(_target_dep ${_third_party_deps}) string(REPLACE " " ";" components "${components}") list(APPEND find_package_args COMPONENTS ${components}) endif() + if(optional_components) + string(REPLACE " " ";" optional_components "${optional_components}") + list(APPEND find_package_args OPTIONAL_COMPONENTS ${optional_components}) + endif() if(is_optional) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) diff --git a/cmake/QtPluginDependencies.cmake.in b/cmake/QtPluginDependencies.cmake.in index f64cc77714..dfa642cc50 100644 --- a/cmake/QtPluginDependencies.cmake.in +++ b/cmake/QtPluginDependencies.cmake.in @@ -8,6 +8,7 @@ foreach(_target_dep ${_third_party_deps}) list(GET _target_dep 1 is_optional) list(GET _target_dep 2 version) list(GET _target_dep 3 components) + list(GET _target_dep 4 optional_components) set(find_package_args "${pkg}") if(version) list(APPEND find_package_args "${version}") @@ -16,6 +17,10 @@ foreach(_target_dep ${_third_party_deps}) string(REPLACE " " ";" components "${components}") list(APPEND find_package_args COMPONENTS ${components}) endif() + if(optional_components) + string(REPLACE " " ";" optional_components "${optional_components}") + list(APPEND find_package_args OPTIONAL_COMPONENTS ${optional_components}) + endif() if(is_optional) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake index e17bf8840e..1cfba15be2 100644 --- a/cmake/QtPostProcessHelpers.cmake +++ b/cmake/QtPostProcessHelpers.cmake @@ -57,8 +57,14 @@ macro(qt_collect_third_party_deps target) set(package_components "") endif() + get_target_property(package_optional_components ${dep} + INTERFACE_QT_PACKAGE_OPTIONAL_COMPONENTS) + if(NOT package_optional_components) + set(package_optional_components "") + endif() + list(APPEND third_party_deps - "${package_name}\;${package_is_optional}\;${package_version}\;${package_components}") + "${package_name}\;${package_is_optional}\;${package_version}\;${package_components}\;${package_optional_components}") endif() endif() endforeach() |