From bd4726fa5d553b8e84ff15f7d24ff6620beb32af Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 20 Jul 2020 17:16:04 +0200 Subject: [PATCH] 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 --- cmake/QtFeature.cmake | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 1ac23200c8f..5058a7f86b4 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -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}")