CMake: Fix configuring standalone tests with a cross-compiled Qt

The Qt6 package needs to be found before calling
qt_build_internals_set_up_private_api, otherwise it will fail when
using a cross-compiled Qt, because QT_HOST_PATH will not be set.

The error is:

CMake Error at qtbase/cmake/QtBuildHelpers.cmake:341 (message):
  You need to set QT_HOST_PATH to cross compile Qt.
Call Stack (most recent call first):
  cmake/QtBuildHelpers.cmake:444 (qt_internal_check_host_path_set_for_cross_compiling)
  cmake/QtBuild.cmake:4 (qt_internal_setup_build_and_global_variables)
  cmake/QtSetup.cmake:6 (include)
  cmake/QtBuildRepoHelpers.cmake:21 (include)
  lib/cmake/Qt6BuildInternals/QtStandaloneTestTemplateProject/Main.cmake:7 (qt_build_internals_set_up_private_api)
  cmake/QtBuildRepoHelpers.cmake:1036 (include)
  cmake/QtBuildRepoHelpers.cmake:1053 (qt_internal_setup_standalone_test_when_called_as_a_find_package_component)
  lib/cmake/Qt6BuildInternals/Qt6BuildInternalsConfig.cmake:68 (qt_internal_setup_build_internals)
  CMakeLists.txt:11 (find_package)

Pick-to: 6.5 6.7 6.8
Fixes: QTBUG-127668
Change-Id: I2fb3df05ce7aed3949d428d98657fe61de723abd
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2024-08-01 17:00:41 +02:00
parent e54fa3c756
commit 4f9da08b05

View File

@ -3,7 +3,16 @@
# Includes QtSetup and friends for private CMake API.
set(QT_INTERNAL_IS_STANDALONE_TEST TRUE)
# Checks minimum CMake version and upgrades policies.
qt_internal_project_setup()
# Look for the Qt6 package before trying to call qt_build_internals_set_up_private_api,
# otherwise it will fail when using a cross-compiled Qt, because QT_HOST_PATH will not be set.
# QT_HOST_PATH is set by Qt6Dependencies.cmake.
find_package(Qt6 REQUIRED)
# Includes QtSetup.cmake.
qt_build_internals_set_up_private_api()
# Find all StandaloneTestsConfig.cmake files, and include them