CMake: Don't process SIMD OSX_ARCHITECTURES on non-Apple platforms

If a user accidentally passes 'CMAKE_OSX_ARCHITECTURES=x86_64;arm64'
to configure on a Linux x86_64 platform, the build would fail when
compiling qdrawhelper_avx2.cpp.o either due to an architecture
mismatch, or due to not recognizing the -Xarch flag on older gcc
compilers.

Only add xarch flags to SIMD compilation on Apple platforms.

Pick-to: 6.8
Change-Id: I322316979626b04cb0378f4dbf3cc26ec96183ac
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Alexandru Croitor 2024-09-13 14:27:24 +02:00
parent a30c1bcd3c
commit 3f3d8604e6

View File

@ -77,16 +77,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})
# Only process OSX_ARCHITECTURES when targeting Apple platforms, otherwise it might fail
# non-Apple builds when CMAKE_OSX_ARCHITECTURES is accidentally passed to configure.
if(APPLE)
# 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)
# 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()
endif()
# The manual loop is done on purpose. Check Gerrit comments for