diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-07-13 15:11:40 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-07-18 16:21:18 +0200 |
commit | 7853f80e39912460421df4e255fed8e91ca9915a (patch) | |
tree | bc1f7c84fecf4c723944ec3e3ea077c360b2310f /cmake/QtPublicDependencyHelpers.cmake | |
parent | 2d2cf95fe12735a5fe7d8137f3b86c113282b8a9 (diff) |
CMake: Extract package dependency finding into functions
Aside from moving the code to reduce duplication, the only changes in
the code are the replacement of @target@ to ${target}, using IN LISTS
with variable names to avoid macro expansion issues and replacing
the if(var) conditions with double variable evaluation
+ NOT STREQUAL "".
The function implementations are now in the same order as they
are used in the Dependencies.cmake files.
Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: Iaae926414fd2a7cc09c2f5716376caaa0aade74b
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake/QtPublicDependencyHelpers.cmake')
-rw-r--r-- | cmake/QtPublicDependencyHelpers.cmake | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/cmake/QtPublicDependencyHelpers.cmake b/cmake/QtPublicDependencyHelpers.cmake index a1e422107a..eb41ff1e23 100644 --- a/cmake/QtPublicDependencyHelpers.cmake +++ b/cmake/QtPublicDependencyHelpers.cmake @@ -1,3 +1,82 @@ +# Note that target_dep_list does not accept a list of values, but a var name that contains the +# list of dependencies. See foreach block for reference. +macro(_qt_internal_find_third_party_dependencies target target_dep_list) + foreach(__qt_${target}_target_dep IN LISTS ${target_dep_list}) + list(GET __qt_${target}_target_dep 0 __qt_${target}_pkg) + list(GET __qt_${target}_target_dep 1 __qt_${target}_is_optional) + list(GET __qt_${target}_target_dep 2 __qt_${target}_version) + list(GET __qt_${target}_target_dep 3 __qt_${target}_components) + list(GET __qt_${target}_target_dep 4 __qt_${target}_optional_components) + set(__qt_${target}_find_package_args "${__qt_${target}_pkg}") + if(__qt_${target}_version) + list(APPEND __qt_${target}_find_package_args "${__qt_${target}_version}") + endif() + if(__qt_${target}_components) + string(REPLACE " " ";" __qt_${target}_components "${__qt_${target}_components}") + list(APPEND __qt_${target}_find_package_args COMPONENTS ${__qt_${target}_components}) + endif() + if(__qt_${target}_optional_components) + string(REPLACE " " ";" + __qt_${target}_optional_components "${__qt_${target}_optional_components}") + list(APPEND __qt_${target}_find_package_args + OPTIONAL_COMPONENTS ${__qt_${target}_optional_components}) + endif() + + if(__qt_${target}_is_optional) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + list(APPEND __qt_${target}_find_package_args QUIET) + endif() + find_package(${__qt_${target}_find_package_args}) + else() + find_dependency(${__qt_${target}_find_package_args}) + endif() + endforeach() +endmacro() + +# Note that target_dep_list does not accept a list of values, but a var name that contains the +# list of dependencies. See foreach block for reference. +macro(_qt_internal_find_tool_dependencies target target_dep_list) + if(NOT "${${target_dep_list}}" STREQUAL "" AND NOT "${QT_HOST_PATH}" STREQUAL "") + # Make sure that the tools find the host tools first + set(BACKUP_${target}_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) + set(BACKUP_${target}_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH}) + list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH_CMAKE_DIR}" + "${_qt_additional_host_packages_prefix_paths}") + list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}" + "${_qt_additional_host_packages_root_paths}") + endif() + + foreach(__qt_${target}_target_dep IN LISTS ${target_dep_list}) + list(GET __qt_${target}_target_dep 0 __qt_${target}_pkg) + list(GET __qt_${target}_target_dep 1 __qt_${target}_version) + + unset(__qt_${target}_find_package_args) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + list(APPEND __qt_${target}_find_package_args QUIET) + endif() + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + list(APPEND __qt_${target}_find_package_args REQUIRED) + endif() + find_package(${__qt_${target}_pkg} + ${__qt_${target}_version} + ${__qt_${target}_find_package_args} + PATHS + ${_qt_additional_packages_prefix_paths} + ) + if (NOT ${__qt_${target}_pkg}_FOUND) + if(NOT "${QT_HOST_PATH}" STREQUAL "") + set(CMAKE_PREFIX_PATH ${BACKUP_${target}_CMAKE_PREFIX_PATH}) + set(CMAKE_FIND_ROOT_PATH ${BACKUP_${target}_CMAKE_FIND_ROOT_PATH}) + endif() + return() + endif() + endforeach() + if(NOT "${${target_dep_list}}" STREQUAL "" AND NOT "${QT_HOST_PATH}" STREQUAL "") + set(CMAKE_PREFIX_PATH ${BACKUP_${target}_CMAKE_PREFIX_PATH}) + set(CMAKE_FIND_ROOT_PATH ${BACKUP_${target}_CMAKE_FIND_ROOT_PATH}) + endif() +endmacro() + # 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. |