diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 722ac159238..fd08b2f181a 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -48,58 +48,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) @@ -127,6 +75,16 @@ include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFindPackageHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicDependencyHelpers.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 86b8edacd49..d18312000f9 100644 --- a/cmake/QtPublicCMakeHelpers.cmake +++ b/cmake/QtPublicCMakeHelpers.cmake @@ -18,3 +18,45 @@ function(_qt_internal_copy_file_if_different_command out_var src_file dst_file) ) endif() 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()