Commit dc1a421c for xz
commit dc1a421ce35f10b9a0c00d1bd42f1fdac0c3e9eb
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Wed Dec 10 16:49:55 2025 +0200
tuklib_integer: Use CMAKE_C_COMPILER_ARCHITECTURE_ID when available
CMake >= 4.1 sets CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID on many
platforms. The list of possible values are documented. Use this
variable when available. On older CMake versions CMAKE_SYSTEM_PROCESSOR
is still used, thus the regexes have to include values like ^amd64 still.
With old CMake versions, checking CMAKE_C_COMPILER_ARCHITECTURE_ID
is somewhat useful with MSVC because CMAKE_SYSTEM_PROCESSOR might
not match the target architecture.
diff --git a/cmake/tuklib_integer.cmake b/cmake/tuklib_integer.cmake
index c2cd04e4..7e8a14ea 100644
--- a/cmake/tuklib_integer.cmake
+++ b/cmake/tuklib_integer.cmake
@@ -143,12 +143,23 @@ function(tuklib_integer TARGET_OR_ALL)
# if -mstrict-align or -mno-strict-align is in effect.
# We use heuristics based on compiler output.
#
- # CMake doesn't provide a standardized/normalized list of processor arch
+ # CMake < 4.1 doesn't provide a standardized/normalized list of arch
# names. For example, x86-64 may be "x86_64" (Linux), "AMD64" (Windows),
# or even "EM64T" (64-bit WinXP).
set(FAST_UNALIGNED_GUESS OFF)
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" PROCESSOR)
+ # CMake 4.1 made CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID useful on many
+ # targets. In earlier versions it's still useful with MSVC with which
+ # CMAKE_SYSTEM_PROCESSOR can refer to the build machine.
+ if(NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "")
+ # CMake 4.2.0 docs say that the list typically has only one entry
+ # except possibly on macOS. On macOS, most (all?) archs support
+ # unaligned access. Just pick the first one from the list.
+ list(GET CMAKE_C_COMPILER_ARCHITECTURE_ID 0 PROCESSOR)
+ string(TOLOWER "${PROCESSOR}" PROCESSOR)
+ endif()
+
# There is no ^ in the first regex branch to allow "i" at the beginning
# so it can match "i386" to "i786", and "x86_64".
if(PROCESSOR MATCHES "[x34567]86|^x64|^amd64|^em64t")