diff options
-rw-r--r-- | cmake/QtBaseGlobalTargets.cmake | 5 | ||||
-rw-r--r-- | cmake/QtModuleDependencies.cmake.in | 2 | ||||
-rw-r--r-- | cmake/QtSetup.cmake | 13 | ||||
-rw-r--r-- | cmake/qt.toolchain.cmake.in | 17 |
4 files changed, 25 insertions, 12 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index ec17164153..b630c3fe8d 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -93,7 +93,12 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS # Generate toolchain file for convenience if(QT_HOST_PATH) get_filename_component(init_qt_host_path "${QT_HOST_PATH}" ABSOLUTE) + # TODO: Figure out how to make these relocatable. set(init_qt_host_path "set(QT_HOST_PATH \"${init_qt_host_path}\" CACHE PATH \"\" FORCE)") + get_filename_component(QT_HOST_PATH_CMAKE_DIR + "${Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR}/.." ABSOLUTE) + set(init_qt_host_path_cmake_dir + "set(QT_HOST_PATH_CMAKE_DIR \"${QT_HOST_PATH_CMAKE_DIR}\" CACHE PATH \"\" FORCE)") endif() if(CMAKE_TOOLCHAIN_FILE) diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in index 2396539109..56819f8816 100644 --- a/cmake/QtModuleDependencies.cmake.in +++ b/cmake/QtModuleDependencies.cmake.in @@ -44,7 +44,7 @@ if(QT_HOST_PATH) # 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}") + list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH_CMAKE_DIR}") list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}") endif() diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index ede764b542..a3584190ab 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -165,14 +165,15 @@ option(QT_BUILD_BENCHMARKS "Build Qt Benchmarks" ${__build_benchmarks}) set(QT_HOST_PATH "" CACHE PATH "Installed Qt host directory path, used for cross compiling.") if (CMAKE_CROSSCOMPILING) - if(NOT IS_DIRECTORY ${QT_HOST_PATH}) + if(NOT IS_DIRECTORY "${QT_HOST_PATH}") message(FATAL_ERROR "You need to set QT_HOST_PATH to cross compile Qt.") endif() - list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH}") - list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}") - find_package(Qt${PROJECT_VERSION_MAJOR}HostInfo REQUIRED) - list(POP_FRONT CMAKE_PREFIX_PATH) - list(POP_FRONT CMAKE_FIND_ROOT_PATH) + find_package(Qt${PROJECT_VERSION_MAJOR}HostInfo + CONFIG + REQUIRED + PATHS "${QT_HOST_PATH}" "${QT_HOST_PATH}/lib/cmake" + NO_CMAKE_FIND_ROOT_PATH + NO_DEFAULT_PATH) endif() ## Android platform settings diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in index e7af642c05..c4884e9dfa 100644 --- a/cmake/qt.toolchain.cmake.in +++ b/cmake/qt.toolchain.cmake.in @@ -1,6 +1,7 @@ @init_platform@ @init_qt_host_path@ +@init_qt_host_path_cmake_dir@ @init_original_toolchain_file@ @@ -27,10 +28,16 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../@qt_path_from_cmake_config_dir_to_prefix@ ABSOLUTE) -list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}") +# Compute the path to the installed Qt lib/cmake folder. +# We assume that the Qt toolchain location is inside the CMake Qt6 package, and thus the directory +# one level higher is what we're looking for. +get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) + +# There's a subdirectory check in cmake's cmFindCommon::RerootPaths() function, that doesn't handle +# the case of CMAKE_PREFIX_PATH == CMAKE_FIND_ROOT_PATH for a particular pair of entries. +# Instead of collapsing the search prefix (which is the case when one is a subdir of the other), +# it concatenates them creating an invalid path. Workaround it by setting the root path to the +# Qt install prefix, and the prefix path to the lib/cmake subdir. +list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}") list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}") -if(QT_HOST_PATH) - list(APPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH}") - list(APPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}") -endif() |