From 8ab5a7283295ede0619e26f959d2b69f93260b70 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 17 Jun 2021 12:04:16 +0200 Subject: [PATCH] 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 Fixes: QTBUG-94501 Change-Id: Ib48a7befcb70e20c3f21315897d51d3064b48134 Reviewed-by: Qt CI Bot Reviewed-by: Dominik Holland Reviewed-by: Joerg Bornemann (cherry picked from commit b6c5e0667696c1d4abaf37f2224b2121b72cdebd) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtConfigDependencies.cmake.in | 8 ++++++++ cmake/QtFindPackageHelpers.cmake | 14 ++++++++++++-- cmake/QtModuleDependencies.cmake.in | 5 +++++ cmake/QtPluginDependencies.cmake.in | 5 +++++ cmake/QtPostProcessHelpers.cmake | 8 +++++++- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cmake/QtConfigDependencies.cmake.in b/cmake/QtConfigDependencies.cmake.in index 52d6421b5e2..159d3c020c7 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 fca039549eb..9f8ae1a9a9e 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 e9159a20d28..9729b24df27 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 f64cc77714f..dfa642cc50d 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 e17bf8840ed..1cfba15be21 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()