CMake: Pass CMAKE_OSX_ARCHITECTURES to try_compile on macOS

There was an inconsistency where configuring qtbase on Apple Silicon
with the following command line produced different results rom the
second variant.

$ cmake ../qtbase -DCMAKE_OSX_ARCHITECTURES=arm64
vs
$ CMAKE_OSX_ARCHITECTURES=arm64 cmake ../qtbase

That happened because the CMAKE_OSX_ARCHITECTURES variables was not
passed to project-based try_compile calls. This resulted in compile
tests like SIMD avx to succeeded on Apple silicon, which shouldn't.

To address that, always pass the architecture on macOS if it's
specified.

Change-Id: Ia12e86230cc6e5e11f387e3cbb273d90646ef2e3
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alexandru Croitor 2020-07-20 17:16:04 +02:00
parent 5e0129f63c
commit bd4726fa5d

View File

@ -813,16 +813,18 @@ function(qt_get_platform_try_compile_vars out_var)
endforeach()
# Pass darwin specific options.
if(UIKIT)
if(CMAKE_OSX_ARCHITECTURES)
list(GET CMAKE_OSX_ARCHITECTURES 0 osx_first_arch)
# The architectures need to be passed explicitly to project-based try_compile calls even on
# macOS, so that arm64 compilation works on Apple silicon.
if(CMAKE_OSX_ARCHITECTURES)
list(GET CMAKE_OSX_ARCHITECTURES 0 osx_first_arch)
# Do what qmake does, aka when doing a simulator_and_device build, build the
# target architecture test only with the first given architecture, which should be the
# device architecture, aka some variation of "arm" (armv7, arm64).
list(APPEND flags_cmd_line "-DCMAKE_OSX_ARCHITECTURES:STRING=${osx_first_arch}")
endif()
# Also specify the sysroot, but only if not doing a simulator_and_device build.
# Do what qmake does, aka when doing a simulator_and_device build, build the
# target architecture test only with the first given architecture, which should be the
# device architecture, aka some variation of "arm" (armv7, arm64).
list(APPEND flags_cmd_line "-DCMAKE_OSX_ARCHITECTURES:STRING=${osx_first_arch}")
endif()
if(UIKIT)
# Specify the sysroot, but only if not doing a simulator_and_device build.
# So keep the sysroot empty for simulator_and_device builds.
if(QT_UIKIT_SDK)
list(APPEND flags_cmd_line "-DCMAKE_OSX_SYSROOT:STRING=${QT_UIKIT_SDK}")