refactor(CMake): Improve ARM target detection, deprecate powerpc (#24329)

Co-authored-by: Shauren <shauren.trinity@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Thelsen
2026-01-11 20:43:41 +01:00
committed by GitHub
parent 71cc99f1a9
commit 1b35971f00
6 changed files with 69 additions and 42 deletions

View File

@@ -40,39 +40,39 @@ target_include_directories(sfmt
target_compile_definitions(sfmt PUBLIC -DSFMT_MEXP=19937)
# enable SIMD instructions if available
include(CheckCCompilerFlag)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(powerpc|ppc)64|(powerpc|ppc)64le")
check_c_compiler_flag("-maltivec" HAVE_ALTIVEC)
if (HAVE_ALTIVEC)
target_compile_options(sfmt PRIVATE -mabi=altivec -maltivec)
target_compile_definitions(sfmt PUBLIC -DHAVE_ALTIVEC)
else ()
message(WARNING "Altivec not available - performance will be poor!")
endif ()
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
check_c_compiler_flag(-mfpu=neon HAVE_NEON)
if (HAVE_NEON)
target_compile_options(sfmt PRIVATE -mfpu=neon -ftree-vectorize)
target_compile_definitions(sfmt PUBLIC -DHAVE_NEON)
else ()
message(WARNING "Neon not available - performance will be poor!")
endif ()
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
check_c_compiler_flag(-march=armv8-a+simd HAVE_NEON)
if (HAVE_NEON)
target_compile_options(sfmt PRIVATE -ftree-vectorize)
target_compile_definitions(sfmt PUBLIC -DHAVE_NEON)
else ()
message(WARNING "Neon not available - performance will be poor!")
endif ()
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "i686|amd64|x86_64|AMD64")
#SSE2 is always available
set(HAVE_SSE2 1)
include(CheckCXXCompilerFlag)
if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
# MSVC does not have any flags to check
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if (ACORE_SYSTEM_PROCESSOR MATCHES "^arm")
set(HAVE_NEON 1)
else ()
set(HAVE_SSE2 1)
endif ()
else ()
if (ACORE_SYSTEM_PROCESSOR STREQUAL "arm")
check_cxx_compiler_flag(-mfpu=neon HAVE_NEON)
if (HAVE_NEON)
target_compile_options(sfmt PRIVATE -mfpu=neon -ftree-vectorize)
endif()
elseif (ACORE_SYSTEM_PROCESSOR STREQUAL "arm64")
check_cxx_compiler_flag(-march=armv8-a+simd HAVE_NEON)
if (HAVE_NEON)
target_compile_options(sfmt PRIVATE -ftree-vectorize)
endif ()
elseif (ACORE_SYSTEM_PROCESSOR MATCHES "x86|amd64")
#SSE2 is always available
set(HAVE_SSE2 1)
target_compile_options(sfmt PRIVATE -msse2)
endif ()
target_compile_definitions(sfmt PUBLIC -DHAVE_SSE2)
endif ()
if (HAVE_NEON)
target_compile_definitions(sfmt PUBLIC HAVE_NEON)
endif ()
if (HAVE_SSE2)
target_compile_definitions(sfmt PUBLIC HAVE_SSE2)
endif ()
set_target_properties(sfmt PROPERTIES LINKER_LANGUAGE CXX)

View File

@@ -12,12 +12,12 @@
file(GLOB_RECURSE sources *.c)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
list(REMOVE_ITEM sources
${CMAKE_CURRENT_SOURCE_DIR}/argon2/opt.c)
else()
if(ACORE_SYSTEM_PROCESSOR MATCHES "x86|amd64")
list(REMOVE_ITEM sources
${CMAKE_CURRENT_SOURCE_DIR}/argon2/ref.c)
else()
list(REMOVE_ITEM sources
${CMAKE_CURRENT_SOURCE_DIR}/argon2/opt.c)
endif()
add_library(argon2 STATIC

View File

@@ -30,7 +30,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT NOJEM)
set(JEM_MADFREE_DEF "#undef")
endif()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
if(ACORE_SYSTEM_PROCESSOR MATCHES "arm")
set(JEM_CPU_SPINWAIT "")
set(JEM_HAVE_CPU_SPINWAIT 0)
else()