CMake: Don't build cmake build tests as macOS universal

We want standalone tests added by qt_internal_add_test to be built as
universal executables, so we can build them on an intel machine and
run them on an ARM machine.

But CMake build tests will be built on the final machine that runs the
tests and it might lack a universal SDK. That's why they should be
built only targeting the architecture of the machine they're running
on.

Change the generated qt.tooclhain.cmake file to allow opting in or out
of building projects with the same architectures as Qt was configured
with.

Now standalone tests will be multi-arch, but CMake build tests will be
single-arch.

Amends e379147f9571af8c3af5768b9040e0180819a855

Task-number: QTBUG-85447
Task-number: QTBUG-87580
Task-number: QTBUG-92933
Change-Id: I41ab047983115f84eb2333cc9ac2d19ca08d621f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2021-05-07 16:25:27 +02:00
parent b0e8c52fd4
commit 0d8eb8a5ab
2 changed files with 17 additions and 4 deletions

View File

@ -130,11 +130,13 @@ function(qt_internal_create_toolchain_file)
# When building another qt repo, ensure the same list of architectures is used by default.
# Detection of a qt repo is done by checking for QT_REPO_MODULE_VERSION which is set in
# the repo's .cmake.conf file.
# Standalone tests will be not be built with multiple architectures to avoid issues in the
# CI when trying to run cmake build tests on VMs that do not have a universal macOS
# Most standalone tests will also be built with multiple architectures.
# Certain tests will be built with a single arch only (like tests/auto/cmake) to avoid
# issues in the CI when trying to build them on VMs that do not have a universal macOS
# SDK.
list(APPEND init_platform "# Only build multiple architectures when building Qt itself")
list(APPEND init_platform "if((QT_REPO_MODULE_VERSION AND NOT QT_BUILD_STANDALONE_TESTS) OR QT_FORCE_QT_OSX_ARCHITECTURES)")
list(APPEND init_platform
"# Only build multiple architectures when building Qt itself. Can be explicitly enabled or disabled.")
list(APPEND init_platform "if((QT_REPO_MODULE_VERSION AND NOT QT_FORCE_SINGLE_QT_OSX_ARCHITECTURE) OR QT_FORCE_ALL_QT_OSX_ARCHITECTURES)")
list(APPEND init_platform " set(__qt_toolchain_building_qt_repo TRUE)")
list(APPEND init_platform " set(CMAKE_OSX_ARCHITECTURES \"\${QT_OSX_ARCHITECTURES}\" CACHE STRING \"\")")
list(APPEND init_platform "endif()")

View File

@ -50,6 +50,17 @@ if (NO_DBUS)
list(APPEND BUILD_OPTIONS_LIST "-DNO_DBUS=True")
endif()
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
list(LENGTH CMAKE_OSX_ARCHITECTURES osx_arch_count)
# When Qt is built as universal config (macOS or iOS), force CMake build tests to build one
# architecture instead of all of them, because the build machine that builds the cmake tests
# might not have a universal SDK installed.
if(osx_arch_count GREATER 1)
list(APPEND BUILD_OPTIONS_LIST "-DQT_FORCE_SINGLE_QT_OSX_ARCHITECTURE=ON")
endif()
endif()
foreach(module ${CMAKE_MODULES_UNDER_TEST})
list(APPEND BUILD_OPTIONS_LIST
"-DCMAKE_${module}_MODULE_MAJOR_VERSION=${CMAKE_${module}_MODULE_MAJOR_VERSION}"