diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-03-24 16:03:35 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-04-01 18:14:59 +0200 |
commit | 659817e287c0948829b8d3c4239cc7fa6fcf70a2 (patch) | |
tree | 2ce7819d6f080dc8b113dbfd1a79ee9443538229 /cmake/QtFeature.cmake | |
parent | 6fd8748f882fad4968f7da1edc65165a78377447 (diff) |
CMake: Fix building multi-arch universal macOS Qt
Use the same approach we use for iOS, which is to set multiple
CMAKE_OSX_ARCHITECTURES values and let the clang front end
deal with lipo-ing the final libraries.
For now, Qt can be configured to build universal macOS libraries by
passing 2 architectures to CMake, either via:
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
or
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
Currently we recommend specifying the intel x86_64 arch as the first
one, to get an intel slice configuration that is comparable to a
non-universal intel build.
Specifying the arm64 slice first could pessimize optimizations and
reduce the feature set for the intel slice due to the limitation
that we run configure tests only once.
The first specified architecture is the one used to do all the
configure tests.
It 'mostly' defines the common feature set of both architecture
slices, with the excepion of some special handling for sse2 and
neon instructions.
In the future we might want to run at least the Qt architecture config
test for all specified architectures, so that we can extract all the
supported sub-arches and instruction sets in a reliable way.
For now, we use the same sse2 hack as for iOS simulator_and_device
builds, otherwise QtGui fails to link due to missing
qt_memfill32_sse2 and other symbols.
The hack is somewhat augmented to ensure that reconfiguration
still succeeds (same issue happened with iOS). Previously the sse2
feature condition was broken due to force setting the feature
to be ON. Now the condition also checks for a special
QT_FORCE_FEATURE_sse2 variable which we set internally.
Note that we shouldn't build for arm64e, because the binaries
get killed when running on AS with the following message:
kernel: exec_mach_imgact: not running binary built against
preview arm64e ABI.
Aslo, by default, we disable the arm64 slice for qt sql plugins,
mostly because the CI provisioned sql libraries that we depend on only
contain x86_64 slices, and trying to build the sql plugins for both
slices will fail with linker errors.
This behavior can be disabled for all targets marked by
qt_internal_force_macos_intel_arch, by setting the
QT_FORCE_MACOS_ALL_ARCHES CMake option to ON.
To disble it per-target one can set
QT_FORCE_MACOS_ALL_ARCHES_${target} to ON.
Task-number: QTBUG-85447
Change-Id: Iccb5dfcc1a21a8a8292bd3817df0ea46c3445f75
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'cmake/QtFeature.cmake')
-rw-r--r-- | cmake/QtFeature.cmake | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 75a9d91560..7f4a9d8b52 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -544,10 +544,10 @@ function(qt_feature_module_end) # Evaluate custom cache assignments. foreach(cache_var_name ${__QtFeature_custom_enabled_cache_variables}) - set(${cache_var_name} ON CACHE BOOL "Force enabled by platform." FORCE) + set(${cache_var_name} ON CACHE BOOL "Force enabled by platform requirements." FORCE) endforeach() foreach(cache_var_name ${__QtFeature_custom_disabled_cache_variables}) - set(${cache_var_name} OFF CACHE BOOL "Force disabled by platform." FORCE) + set(${cache_var_name} OFF CACHE BOOL "Force disabled by platform requirements." FORCE) endforeach() set(enabled_public_features "") @@ -890,9 +890,8 @@ function(qt_get_platform_try_compile_vars out_var) # Pass darwin specific options. # 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) - + qt_internal_get_first_osx_arch(osx_first_arch) + if(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). @@ -909,6 +908,16 @@ function(qt_get_platform_try_compile_vars out_var) set("${out_var}" "${flags_cmd_line}" PARENT_SCOPE) endfunction() +# Set out_var to the first value of CMAKE_OSX_ARCHITECTURES. +# Sets an empty string if no architecture is present. +function(qt_internal_get_first_osx_arch out_var) + set(value "") + if(CMAKE_OSX_ARCHITECTURES) + list(GET CMAKE_OSX_ARCHITECTURES 0 value) + endif() + set(${out_var} "${value}" PARENT_SCOPE) +endfunction() + function(qt_config_compile_test_x86simd extension label) if (DEFINED TEST_X86SIMD_${extension}) return() |