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>
This commit is contained in:
Alexandru Croitor 2021-06-17 12:04:16 +02:00
parent 7e335f290b
commit b6c5e06676
5 changed files with 37 additions and 3 deletions

View File

@ -10,6 +10,7 @@ foreach(_target_dep ${_third_party_deps})
list(GET _target_dep 1 is_optional) list(GET _target_dep 1 is_optional)
list(GET _target_dep 2 version) list(GET _target_dep 2 version)
list(GET _target_dep 3 components) list(GET _target_dep 3 components)
list(GET _target_dep 4 optional_components)
set(find_package_args "${pkg}") set(find_package_args "${pkg}")
if(version) if(version)
list(APPEND find_package_args "${version}") list(APPEND find_package_args "${version}")
@ -18,6 +19,10 @@ foreach(_target_dep ${_third_party_deps})
string(REPLACE " " ";" components "${components}") string(REPLACE " " ";" components "${components}")
list(APPEND find_package_args COMPONENTS ${components}) list(APPEND find_package_args COMPONENTS ${components})
endif() 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. # Already build an error message, because find_dependency calls return() on failure.
set(__@INSTALL_CMAKE_NAMESPACE@_message "\nPackage: ${pkg}") set(__@INSTALL_CMAKE_NAMESPACE@_message "\nPackage: ${pkg}")
@ -27,6 +32,9 @@ foreach(_target_dep ${_third_party_deps})
if(components) if(components)
string(APPEND __@INSTALL_CMAKE_NAMESPACE@_message "\nComponents: ${components}") string(APPEND __@INSTALL_CMAKE_NAMESPACE@_message "\nComponents: ${components}")
endif() endif()
if(optional_components)
string(APPEND __@INSTALL_CMAKE_NAMESPACE@_message "\nComponents: ${optional_components}")
endif()
set(@INSTALL_CMAKE_NAMESPACE@_DEPENDENCY_NOT_FOUND_MESSAGE set(@INSTALL_CMAKE_NAMESPACE@_DEPENDENCY_NOT_FOUND_MESSAGE
"${__@INSTALL_CMAKE_NAMESPACE@_message}") "${__@INSTALL_CMAKE_NAMESPACE@_message}")

View File

@ -18,7 +18,7 @@ macro(qt_find_package)
set(find_package_options CONFIG NO_MODULE MODULE REQUIRED) set(find_package_options CONFIG NO_MODULE MODULE REQUIRED)
set(options ${find_package_options} MARK_OPTIONAL) set(options ${find_package_options} MARK_OPTIONAL)
set(oneValueArgs MODULE_NAME QMAKE_LIB) 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}) cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# If some Qt internal project calls qt_find_package(WrapFreeType), but WrapFreeType was already # 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. # Re-append components to forward them.
list(APPEND arg_UNPARSED_ARGUMENTS "COMPONENTS;${arg_COMPONENTS}") list(APPEND arg_UNPARSED_ARGUMENTS "COMPONENTS;${arg_COMPONENTS}")
endif() 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. # Don't look for packages in PATH if requested to.
if(QT_NO_USE_FIND_PACKAGE_SYSTEM_ENVIRONMENT_PATH) 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}) PROPERTY INTERFACE_QT_PACKAGE_COMPONENTS ${components_as_string})
endif() 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 get_property(is_global TARGET ${qt_find_package_target_name} PROPERTY
IMPORTED_GLOBAL) IMPORTED_GLOBAL)
qt_internal_should_not_promote_package_target_to_global( qt_internal_should_not_promote_package_target_to_global(

View File

@ -22,6 +22,7 @@ foreach(_target_dep ${_third_party_deps})
list(GET _target_dep 1 is_optional) list(GET _target_dep 1 is_optional)
list(GET _target_dep 2 version) list(GET _target_dep 2 version)
list(GET _target_dep 3 components) list(GET _target_dep 3 components)
list(GET _target_dep 4 optional_components)
set(find_package_args "${pkg}") set(find_package_args "${pkg}")
if(version) if(version)
list(APPEND find_package_args "${version}") list(APPEND find_package_args "${version}")
@ -30,6 +31,10 @@ foreach(_target_dep ${_third_party_deps})
string(REPLACE " " ";" components "${components}") string(REPLACE " " ";" components "${components}")
list(APPEND find_package_args COMPONENTS ${components}) list(APPEND find_package_args COMPONENTS ${components})
endif() endif()
if(optional_components)
string(REPLACE " " ";" optional_components "${optional_components}")
list(APPEND find_package_args OPTIONAL_COMPONENTS ${optional_components})
endif()
if(is_optional) if(is_optional)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)

View File

@ -8,6 +8,7 @@ foreach(_target_dep ${_third_party_deps})
list(GET _target_dep 1 is_optional) list(GET _target_dep 1 is_optional)
list(GET _target_dep 2 version) list(GET _target_dep 2 version)
list(GET _target_dep 3 components) list(GET _target_dep 3 components)
list(GET _target_dep 4 optional_components)
set(find_package_args "${pkg}") set(find_package_args "${pkg}")
if(version) if(version)
list(APPEND find_package_args "${version}") list(APPEND find_package_args "${version}")
@ -16,6 +17,10 @@ foreach(_target_dep ${_third_party_deps})
string(REPLACE " " ";" components "${components}") string(REPLACE " " ";" components "${components}")
list(APPEND find_package_args COMPONENTS ${components}) list(APPEND find_package_args COMPONENTS ${components})
endif() endif()
if(optional_components)
string(REPLACE " " ";" optional_components "${optional_components}")
list(APPEND find_package_args OPTIONAL_COMPONENTS ${optional_components})
endif()
if(is_optional) if(is_optional)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)

View File

@ -57,8 +57,14 @@ macro(qt_collect_third_party_deps target)
set(package_components "") set(package_components "")
endif() 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 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()
endif() endif()
endforeach() endforeach()