Skip to content

Commit

Permalink
CMake: Handle OPTIONAL_COMPONENTS in qt_find_package
Browse files Browse the repository at this point in the history
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 07b6d33

Pick-to: 6.1 6.2
Fixes: QTBUG-94501
Change-Id: Ib48a7befcb70e20c3f21315897d51d3064b48134
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Dominik Holland <[email protected]>
Reviewed-by: Joerg Bornemann <[email protected]>
  • Loading branch information
alcroito committed Jun 17, 2021
1 parent 7e335f2 commit b6c5e06
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmake/QtConfigDependencies.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}")
Expand All @@ -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}")

Expand Down
14 changes: 12 additions & 2 deletions cmake/QtFindPackageHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions cmake/QtModuleDependencies.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmake/QtPluginDependencies.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion cmake/QtPostProcessHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b6c5e06

Please sign in to comment.