CMake: Allow enabling/disabling QT_HOST_PATH checks via variable

One can now pass -DQT_REQUIRE_HOST_PATH_CHECK=OFF or
-DQT_REQUIRE_HOST_PATH_CHECK=ON to force disable or enable
the QT_HOST_PATH and QT_HOST_CMAKE_DIR_PATH validity checks.

One potential use case is if a project wants to manually find
QtFooTools packages by manipulating CMAKE_FIND_ROOT_PATH and such,
in which case they might not want to pass a QT_HOST_PATH.

Another potential use case is cross-building Qt with
-DQT_BUILD_TOOLS_WHEN_CROSSCOMPILING=ON and allowing the same
generated toolchain file to be used on the device image.

By default the generated toolchain file would require a host path
because it expects that it's still being used for cross-compiling.
But once the toolchain file is deployed to the device there's no need
to use the host tools anymore.

Another use case is building a desktop Qt using the host tools of
another desktop Qt. The new desktop Qt can use its newly built tools
just fine and wouldn't need the original desktop Qt tools.

QT_REQUIRE_HOST_PATH_CHECK needs to be added the list of vars to pass
through to try_compile calls.

Change-Id: I4b922b5d854828e6b9210dd8c07b4b1b8630aad1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Craig Scott <craig.scott@qt.io>
This commit is contained in:
Alexandru Croitor 2021-10-22 12:31:39 +02:00
parent f917df2752
commit b04a0f0c04

View File

@ -5,6 +5,7 @@ set(__qt_toolchain_used_variables
QT_TOOLCHAIN_RELOCATABLE_PREFIX
QT_HOST_PATH
QT_HOST_PATH_CMAKE_DIR
QT_REQUIRE_HOST_PATH_CHECK
)
@init_additional_used_variables@
@ -142,7 +143,12 @@ endif()
# Set up QT_HOST_PATH and do sanity checks.
# A host path is required when cross-compiling but optional when doing a native build.
set(__qt_toolchain_host_path_required "@qt_host_path_required@")
# Requiredness can be overridden via variable.
if(DEFINED QT_REQUIRE_HOST_PATH_CHECK)
set(__qt_toolchain_host_path_required "${QT_REQUIRE_HOST_PATH_CHECK}")
else()
set(__qt_toolchain_host_path_required "@qt_host_path_required@")
endif()
set(__qt_toolchain_initial_qt_host_path
"@qt_host_path_absolute@")
set(__qt_toolchain_initial_qt_host_path_cmake_dir