From 59f0f25f7161313988b2c40f3c26b8ee12a88877 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 13 Sep 2022 17:27:42 +0200 Subject: [PATCH] CMake: Move __qt_internal_collect_additional_prefix_paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move it out of QtConfig.cmake.in into QtPublicCMakeHelpers.cmake so that the Qt6Config file is less cluttered. Pick-to: 6.4 Change-Id: I772a0cca35d5c03cd688c3f1de34984484444105 Reviewed-by: Jörg Bornemann --- cmake/QtConfig.cmake.in | 62 ++++++-------------------------- cmake/QtPublicCMakeHelpers.cmake | 42 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 3127d50858..8834ac4ea6 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -38,58 +38,6 @@ elseif(APPLE AND CMAKE_SYSTEM_NAME STREQUAL "iOS") list(APPEND CMAKE_MODULE_PATH "${__qt_internal_cmake_ios_support_files_path}") endif() -set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING - "Additional directories where find(Qt6 ...) components are searched") -set(QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH "" CACHE STRING - "Additional directories where find(Qt6 ...) host Qt components are searched") - -# Collect additional package prefix paths to look for Qt packages, both from command line and the -# env variable ${prefixes_var}. The result is stored in ${out_var} and is a list of paths ending -# with "/lib/cmake". -function(__qt_internal_collect_additional_prefix_paths out_var prefixes_var) - if(DEFINED "${out_var}") - return() - endif() - - set(additional_packages_prefix_paths "") - - set(additional_packages_prefixes "") - if(${prefixes_var}) - list(APPEND additional_packages_prefixes ${${prefixes_var}}) - endif() - if(DEFINED ENV{${prefixes_var}} - AND NOT "$ENV{${prefixes_var}}" STREQUAL "") - set(prefixes_from_env "$ENV{${prefixes_var}}") - if(NOT CMAKE_HOST_WIN32) - string(REPLACE ":" ";" prefixes_from_env "${prefixes_from_env}") - endif() - list(APPEND additional_packages_prefixes ${prefixes_from_env}) - endif() - - foreach(additional_path IN LISTS additional_packages_prefixes) - file(TO_CMAKE_PATH "${additional_path}" additional_path) - - # The prefix paths need to end with lib/cmake to ensure the packages are found when - # cross compiling. Search for REROOT_PATH_ISSUE_MARKER in the qt.toolchain.cmake file for - # details. - # We must pass the values via the PATHS options because the main find_package call uses - # NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH values are discarded. - # CMAKE_FIND_ROOT_PATH values are not discarded and togegher with the PATHS option, it - # ensures packages from additional prefixes are found. - if(NOT additional_path MATCHES "/lib/cmake$") - string(APPEND additional_path "/lib/cmake") - endif() - list(APPEND additional_packages_prefix_paths "${additional_path}") - endforeach() - - set("${out_var}" "${additional_packages_prefix_paths}" PARENT_SCOPE) -endfunction() - -__qt_internal_collect_additional_prefix_paths(_qt_additional_packages_prefix_paths - QT_ADDITIONAL_PACKAGES_PREFIX_PATH) -__qt_internal_collect_additional_prefix_paths(_qt_additional_host_packages_prefix_paths - QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH) - # Take a list of prefix paths ending with "/lib/cmake", and return a list of absolute paths with # "/lib/cmake" removed. function(__qt_internal_prefix_paths_to_roots out_var prefix_paths) @@ -120,6 +68,16 @@ include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTestHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicToolHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeHelpers.cmake") +set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING + "Additional directories where find(Qt6 ...) components are searched") +set(QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH "" CACHE STRING + "Additional directories where find(Qt6 ...) host Qt components are searched") + +__qt_internal_collect_additional_prefix_paths(_qt_additional_packages_prefix_paths + QT_ADDITIONAL_PACKAGES_PREFIX_PATH) +__qt_internal_collect_additional_prefix_paths(_qt_additional_host_packages_prefix_paths + QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH) + if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE) set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@) endif() diff --git a/cmake/QtPublicCMakeHelpers.cmake b/cmake/QtPublicCMakeHelpers.cmake index 8e781a6364..cc188162e7 100644 --- a/cmake/QtPublicCMakeHelpers.cmake +++ b/cmake/QtPublicCMakeHelpers.cmake @@ -35,3 +35,45 @@ function(_qt_internal_check_depfile_support out_var) endif() set(${out_var} "${${out_var}}" PARENT_SCOPE) endfunction() + +# Collect additional package prefix paths to look for Qt packages, both from command line and the +# env variable ${prefixes_var}. The result is stored in ${out_var} and is a list of paths ending +# with "/lib/cmake". +function(__qt_internal_collect_additional_prefix_paths out_var prefixes_var) + if(DEFINED "${out_var}") + return() + endif() + + set(additional_packages_prefix_paths "") + + set(additional_packages_prefixes "") + if(${prefixes_var}) + list(APPEND additional_packages_prefixes ${${prefixes_var}}) + endif() + if(DEFINED ENV{${prefixes_var}} + AND NOT "$ENV{${prefixes_var}}" STREQUAL "") + set(prefixes_from_env "$ENV{${prefixes_var}}") + if(NOT CMAKE_HOST_WIN32) + string(REPLACE ":" ";" prefixes_from_env "${prefixes_from_env}") + endif() + list(APPEND additional_packages_prefixes ${prefixes_from_env}) + endif() + + foreach(additional_path IN LISTS additional_packages_prefixes) + file(TO_CMAKE_PATH "${additional_path}" additional_path) + + # The prefix paths need to end with lib/cmake to ensure the packages are found when + # cross compiling. Search for REROOT_PATH_ISSUE_MARKER in the qt.toolchain.cmake file for + # details. + # We must pass the values via the PATHS options because the main find_package call uses + # NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH values are discarded. + # CMAKE_FIND_ROOT_PATH values are not discarded and togegher with the PATHS option, it + # ensures packages from additional prefixes are found. + if(NOT additional_path MATCHES "/lib/cmake$") + string(APPEND additional_path "/lib/cmake") + endif() + list(APPEND additional_packages_prefix_paths "${additional_path}") + endforeach() + + set("${out_var}" "${additional_packages_prefix_paths}" PARENT_SCOPE) +endfunction()