diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-03-26 11:52:54 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-04-01 18:14:56 +0200 |
commit | 6fd8748f882fad4968f7da1edc65165a78377447 (patch) | |
tree | 9986e652c01c8756a1ff5df6b4cfc9387cac798e /cmake | |
parent | 0592123a0c68b65c83555dc0f023c4bc77030f31 (diff) |
CMake: Teach qt_internal_add_simd to exclude given osx architectures
qt_internal_add_simd can now take an EXCLUDE_OSX_ARCHITECTURES list of
values which specifies for which architectures the simd compile flags
should not be added.
This is relevant for macOS universal builds.
Example
CMAKE_OSX_ARCHITECTURES is "x86_64;arm64"
EXCLUDE_OSX_ARCHITECTURES is "arm64"
SIMD is avx2
the final compiler flags that will be added are "-Xarch_x86_64 -mavx2"
Slightly, clean up the function implementation and document its
arguments.
NAME handling has been removed because it's dead code that hasn't been
removed as part of 1b7008a3d784f3f266368f824cb43d473a301ba1.
Task-number: QTBUG-85447
Change-Id: I395c19bdd67219bebb6b5b8d9f418b6e6488e09b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtSimdHelpers.cmake | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/cmake/QtSimdHelpers.cmake b/cmake/QtSimdHelpers.cmake index dbbd4b7da0..3e5fea11c8 100644 --- a/cmake/QtSimdHelpers.cmake +++ b/cmake/QtSimdHelpers.cmake @@ -1,9 +1,20 @@ # Handle files that need special SIMD-related flags. -# This creates an object library and makes target link -# to it (privately). +# +# This function adds the passed source files to the given target only if the SIMD specific condition +# evaluates to true. It also adds the SIMD architecture specific flags as compile options to those +# source files. +# +# Arguments +# NAME: is deprecated, don't use it. +# SIMD: name of the simd architecture, e.g. sse2, avx, neon. A Qt feature named QT_FEATURE_foo +# should exist, as well as QT_CFLAGS_foo assignment in QtCompilerOptimization.cmake. +# COMPILE_FLAGS: extra compile flags to set for the passed source files +# EXCLUDE_OSX_ARCHITECTURES: On apple platforms, specifies which architectures should not get the +# SIMD compiler flags. This is mostly relevant for fat / universal builds +# function(qt_internal_add_simd_part target) - qt_parse_all_arguments(arg "qt_add_simd_part" "" "" - "NAME;SIMD;${__default_private_args};COMPILE_FLAGS" ${ARGN}) + qt_parse_all_arguments(arg "qt_add_simd_part" "" "NAME;SIMD" + "${__default_private_args};COMPILE_FLAGS;EXCLUDE_OSX_ARCHITECTURES" ${ARGN}) if ("x${arg_SIMD}" STREQUAL x) message(FATAL_ERROR "qt_add_simd_part needs a SIMD type to be set.") endif() @@ -49,11 +60,6 @@ function(qt_internal_add_simd_part target) list(REMOVE_DUPLICATES simd_flags_expanded) endif() - set(name "${arg_NAME}") - if("x${name}" STREQUAL x) - set(name "${target}_simd_${arg_SIMD}") - endif() - qt_evaluate_config_expression(result ${condition}) if(${result}) if(QT_CMAKE_DEBUG_EXTEND_TARGET) @@ -64,6 +70,20 @@ function(qt_internal_add_simd_part target) set(simd_flags_expanded "${${simd_flags_var_name}}") endif() + # If requested, don't pass the simd specific flags to excluded arches on apple platforms. + # Mostly important for universal / fat builds. + get_target_property(osx_architectures ${target} OSX_ARCHITECTURES) + if(simd_flags_expanded AND osx_architectures AND arg_EXCLUDE_OSX_ARCHITECTURES) + list(REMOVE_ITEM osx_architectures ${arg_EXCLUDE_OSX_ARCHITECTURES}) + + # Assumes that simd_flags_expanded contains only one item on apple platforms. + list(TRANSFORM osx_architectures + REPLACE "^(.+)$" "-Xarch_\\1;${simd_flags_expanded}" + OUTPUT_VARIABLE simd_flags_expanded) + endif() + + # The manual loop is done on purpose. Check Gerrit comments for + # 1b7008a3d784f3f266368f824cb43d473a301ba1. foreach(source IN LISTS arg_SOURCES) set_property(SOURCE "${source}" APPEND PROPERTY COMPILE_OPTIONS |