summaryrefslogtreecommitdiffstats
path: root/cmake/QtToolchainHelpers.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-10-20 15:46:50 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-10-29 15:34:12 +0200
commit102c1cff72b01b8972e4e5f63bce9616e95dc213 (patch)
treea06957c49912777cbeaa980748887868e5c67ef0 /cmake/QtToolchainHelpers.cmake
parentc82bca9efe79a4913499d08d2bc814cb32cfcef9 (diff)
CMake: Clean up and improve QT_HOST_PATH_CMAKE_DIR computation
Previously when one wanted to use a cross-compiled Qt with a host Qt installed in a non-default location, they'd have to provide both QT_HOST_PATH and QT_HOST_PATH_CMAKE_DIR. This change will now try to first check if ${QT_HOST_PATH}/lib/cmake is a valid path on disk and use that. This is nicer to the user because they don't need to specify 2 paths anymore. Furthermore the path computation and sanity checks are now done after any extra toolchain cmake files are loaded, to give an opportunity to the files to set the paths first. Finally, both variables need to be added to __qt_toolchain_used_variables so they are passed along to try_compile calls if the variables are specified manually. Otherwise when the toolchain file is loaded by a try_compile project, it will error out saying no host path found (as long as the initial paths embedded in the toolchain are invalid). Amends 93fc3afe71467ca6aeffa41d7a6f4a170f82b62e and ec90f9013b4c6b63d7e03a964f66f97329be7885 Pick-to: 6.2 Change-Id: I433239b36b084f2d0a7a0dd043fdf87d77c138f3 Reviewed-by: Craig Scott <craig.scott@qt.io>
Diffstat (limited to 'cmake/QtToolchainHelpers.cmake')
-rw-r--r--cmake/QtToolchainHelpers.cmake35
1 files changed, 11 insertions, 24 deletions
diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake
index e7bf2eda56..de8c1e8f52 100644
--- a/cmake/QtToolchainHelpers.cmake
+++ b/cmake/QtToolchainHelpers.cmake
@@ -2,32 +2,19 @@
# as well as CMake application projects.
# Expects various global variables to be set.
function(qt_internal_create_toolchain_file)
- if(NOT "${QT_HOST_PATH}" STREQUAL "")
- # TODO: Figure out how to make these relocatable.
-
- get_filename_component(__qt_host_path_absolute "${QT_HOST_PATH}" ABSOLUTE)
- set(init_qt_host_path "
- set(__qt_initial_qt_host_path \"${__qt_host_path_absolute}\")
- if(NOT DEFINED QT_HOST_PATH AND EXISTS \"\${__qt_initial_qt_host_path}\")
- set(QT_HOST_PATH \"\${__qt_initial_qt_host_path}\" CACHE PATH \"\" FORCE)
- endif()")
+ set(qt_host_path_required FALSE)
- get_filename_component(__qt_host_path_cmake_dir_absolute
+ if(NOT "${QT_HOST_PATH}" STREQUAL "")
+ # If a QT_HOST_PATH is provided when configuring qtbase, we assume it's a cross build
+ # and thus we require the QT_HOST_PATH to be provided also when using the cross-built Qt.
+ # This tells the Qt toolchain file to do appropriate requirement checks.
+ set(qt_host_path_required TRUE)
+
+ # TODO: Figure out how to make the initial QT_HOST_PATH var relocatable in relation
+ # to the target CMAKE_INSTALL_DIR, if at all possible to do so in a reliable way.
+ get_filename_component(qt_host_path_absolute "${QT_HOST_PATH}" ABSOLUTE)
+ get_filename_component(qt_host_path_cmake_dir_absolute
"${Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR}/.." ABSOLUTE)
- set(init_qt_host_path_cmake_dir
- "
- set(__qt_initial_qt_host_path_cmake_dir \"${__qt_host_path_cmake_dir_absolute}\")
- if(NOT DEFINED QT_HOST_PATH_CMAKE_DIR AND EXISTS \"\${__qt_initial_qt_host_path_cmake_dir}\")
- set(QT_HOST_PATH_CMAKE_DIR \"\${__qt_initial_qt_host_path_cmake_dir}\" CACHE PATH \"\" FORCE)
- endif()")
-
- set(init_qt_host_path_checks "
- if(\"\${QT_HOST_PATH}\" STREQUAL \"\" OR NOT EXISTS \"\${QT_HOST_PATH}\")
- message(FATAL_ERROR \"To use a cross-compiled Qt, please specify a path to a host Qt installation by setting the QT_HOST_PATH cache variable.\")
- endif()
- if(\"\${QT_HOST_PATH_CMAKE_DIR}\" STREQUAL \"\" OR NOT EXISTS \"\${QT_HOST_PATH_CMAKE_DIR}\")
- message(FATAL_ERROR \"To use a cross-compiled Qt, please specify a path to a host Qt installation CMake directory by setting the QT_HOST_PATH_CMAKE_DIR cache variable.\")
- endif()")
endif()
if(CMAKE_TOOLCHAIN_FILE)