summaryrefslogtreecommitdiffstats
path: root/cmake/QtPublicCMakeHelpers.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/QtPublicCMakeHelpers.cmake')
-rw-r--r--cmake/QtPublicCMakeHelpers.cmake56
1 files changed, 56 insertions, 0 deletions
diff --git a/cmake/QtPublicCMakeHelpers.cmake b/cmake/QtPublicCMakeHelpers.cmake
index 35cd4fe1f3..6001dfec11 100644
--- a/cmake/QtPublicCMakeHelpers.cmake
+++ b/cmake/QtPublicCMakeHelpers.cmake
@@ -32,3 +32,59 @@ 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()
+
+# 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)
+ set(result "")
+ foreach(path IN LISTS prefix_paths)
+ if(path MATCHES "/lib/cmake$")
+ string(APPEND path "/../..")
+ endif()
+ get_filename_component(path "${path}" ABSOLUTE)
+ list(APPEND result "${path}")
+ endforeach()
+ set("${out_var}" "${result}" PARENT_SCOPE)
+endfunction()