Move dependency lookup functionality to the common macro

Dependency lookup mechanism is the same for modules and plugins. It
makes sense to wrap it using macro.

Pick-to: 6.2
Change-Id: I73727743b0f5f40b2d94624f65ebfcf85e8dcc59
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2021-06-17 16:18:59 +02:00
parent cdbb390c4a
commit ff4244b540
6 changed files with 35 additions and 51 deletions

View File

@ -256,6 +256,7 @@ set(__public_cmake_helpers
cmake/QtPublicTargetHelpers.cmake
cmake/QtPublicWalkLibsHelpers.cmake
cmake/QtPublicFindPackageHelpers.cmake
cmake/QtPublicDependencyHelpers.cmake
)
qt_copy_or_install(FILES ${__public_cmake_helpers} DESTINATION "${__GlobalConfig_install_dir}")

View File

@ -552,7 +552,7 @@ include(QtPublicPluginHelpers)
include(QtPublicTargetHelpers)
include(QtPublicWalkLibsHelpers)
include(QtPublicFindPackageHelpers)
include(QtPublicDependencyHelpers)
# TODO: This block provides support for old variables. It should be removed once
# we remove all references to these variables in other Qt module repos.

View File

@ -60,6 +60,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/QtPublicPluginHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTargetHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicWalkLibsHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFindPackageHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicDependencyHelpers.cmake")
if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE)
set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@)

View File

@ -86,32 +86,10 @@ if(NOT "${QT_HOST_PATH}" STREQUAL "")
set(CMAKE_FIND_ROOT_PATH ${BACKUP_@target@_CMAKE_FIND_ROOT_PATH})
endif()
# TODO: The dependencies lookup mechanism is common for Modules and Plugins.
# It should be moved to the common public helper file.
#
# note: target_deps example: "Qt6Core\;5.12.0;Qt6Gui\;5.12.0"
set(_target_deps "@target_deps@")
foreach(_target_dep ${_target_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if(NOT ${pkg}_FOUND)
set(pkg_names ${pkg})
if(pkg MATCHES "(.*)Private$")
set(pkg_names "${CMAKE_MATCH_1};${pkg}")
endif()
find_dependency(${pkg} ${version}
NAMES
${pkg_names}
PATHS
"${CMAKE_CURRENT_LIST_DIR}/.."
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)
endif()
endforeach()
set(_@target@_target_deps "@target_deps@")
set(_@target@_find_dependency_paths "${CMAKE_CURRENT_LIST_DIR}/..")
_qt_internal_find_dependencies(_@target@_target_deps _@target@_find_dependency_paths)
set(_@QT_CMAKE_EXPORT_NAMESPACE@@target@_MODULE_DEPENDENCIES "@qt_module_dependencies@")
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND TRUE)

View File

@ -37,31 +37,9 @@ if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
set(__qt_use_no_default_path_for_qt_packages "")
endif()
# TODO: The dependencies lookup mechanism is common for Modules and Plugins.
# It should be moved to the common public helper file.
#
# note: target_deps example: "Qt6Core\;5.12.0;Qt6Gui\;5.12.0"
set(_target_deps "@target_deps@")
foreach(_target_dep ${_target_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if (NOT ${pkg}_FOUND)
set(pkg_names ${pkg})
if(pkg MATCHES "(.*)Private$")
set(pkg_names "${CMAKE_MATCH_1};${pkg}")
endif()
find_dependency(${pkg} ${version}
NAMES
${pkg_names}
PATHS
@find_dependency_paths@
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)
endif()
endforeach()
set(_@target@_target_deps "@target_deps@")
set(_@target@_find_dependency_paths "@find_dependency_paths@")
_qt_internal_find_dependencies(_@target@_target_deps _@target@_find_dependency_paths)
set(@target@_FOUND TRUE)

View File

@ -0,0 +1,26 @@
# Please note the target_dep_list accepts not the actual list values but the list names that
# contain preformed dependencies. See foreach block for reference.
# The same applies for find_dependency_path_list.
macro(_qt_internal_find_dependencies target_dep_list find_dependency_path_list)
foreach(target_dep IN LISTS ${target_dep_list})
list(GET target_dep 0 pkg)
list(GET target_dep 1 version)
if (NOT ${pkg}_FOUND)
set(pkg_names ${pkg})
if(pkg MATCHES "(.*)Private$")
set(pkg_names "${CMAKE_MATCH_1};${pkg}")
endif()
find_dependency(${pkg} ${version}
NAMES
${pkg_names}
PATHS
${${find_dependency_path_list}}
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)
endif()
endforeach()
endmacro()