33# Uses target-based approach (modern CMake best practice)
44
55#------------------------------------------------------------------------------
6- # Detect compiler and set appropriate flags
6+ # Detect compiler and architecture
77#------------------------------------------------------------------------------
88set (HPC_IS_GCC FALSE )
99set (HPC_IS_CLANG FALSE )
1010set (HPC_IS_MSVC FALSE )
11+ set (HPC_IS_ARM FALSE )
1112
1213if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
1314 set (HPC_IS_GCC TRUE )
@@ -17,6 +18,11 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
1718 set (HPC_IS_MSVC TRUE )
1819endif ()
1920
21+ # Detect ARM architecture (Apple Silicon, Raspberry Pi, etc.)
22+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM" )
23+ set (HPC_IS_ARM TRUE )
24+ endif ()
25+
2026#------------------------------------------------------------------------------
2127# hpc_set_compiler_options(target)
2228# Sets warning levels and optimization flags for a target
@@ -50,7 +56,15 @@ function(hpc_set_compiler_options target)
5056 endif ()
5157
5258 # Release optimization flags
53- if (HPC_IS_GCC OR HPC_IS_CLANG)
59+ if (HPC_IS_ARM)
60+ # ARM uses -mcpu=native instead of -march=native
61+ target_compile_options (${target} PRIVATE
62+ $<$<CONFIG :Release >:-O3 >
63+ $<$<CONFIG :Release >:-mcpu =native >
64+ $<$<CONFIG :RelWithDebInfo >:-O2 >
65+ $<$<CONFIG :RelWithDebInfo >:-g >
66+ )
67+ elseif (HPC_IS_GCC OR HPC_IS_CLANG)
5468 target_compile_options (${target} PRIVATE
5569 $<$<CONFIG :Release >:-O3 >
5670 $<$<CONFIG :Release >:-march =native >
@@ -103,8 +117,16 @@ endfunction()
103117#------------------------------------------------------------------------------
104118function (hpc_enable_simd target )
105119 cmake_parse_arguments (ARG "SSE;AVX;AVX2;AVX512" "" "" ${ARGN} )
106-
107- if (HPC_IS_GCC OR HPC_IS_CLANG)
120+
121+ if (HPC_IS_ARM)
122+ # ARM uses NEON instead of x86 SIMD
123+ if (HPC_IS_CLANG OR HPC_IS_GCC)
124+ # NEON is enabled by default on AArch64, but we can add march flag
125+ target_compile_options (${target} PRIVATE
126+ $<$<CONFIG :Release >:-mcpu =native >
127+ )
128+ endif ()
129+ elseif (HPC_IS_GCC OR HPC_IS_CLANG)
108130 if (ARG_SSE)
109131 target_compile_options (${target} PRIVATE -msse4.2 )
110132 endif ()
@@ -124,7 +146,6 @@ function(hpc_enable_simd target)
124146 if (ARG_AVX2 OR ARG_AVX512)
125147 target_compile_options (${target} PRIVATE /arch:AVX2 )
126148 endif ()
127- # Note: MSVC uses /arch:AVX512 only in newer versions
128149 endif ()
129150endfunction ()
130151
0 commit comments