@@ -153,19 +153,46 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
153153 set (FEAT_INPUT_FILE "/dev/null" )
154154 endif ()
155155
156+ # CMAKE_C_COMPILER is already set by the NDK toolchain to the correct generic clang.exe
157+ set (NDK_C_COMPILER_PATH "${CMAKE_C_COMPILER} " )
158+ message (NOTICE "NDK C Compiler Path: ${NDK_C_COMPILER_PATH} " )
159+
160+ # Construct the full command list for execute_process
161+ set (COMPILER_COMMAND_LIST "${NDK_C_COMPILER_PATH} " )
162+
163+ # Add the crucial --target argument for cross-compilation
164+ # For arm64-v8a, the target triple is aarch64-linux-android
165+ list (APPEND COMPILER_COMMAND_LIST "--target=aarch64-linux-android" )
166+
167+ # Add the crucial --sysroot argument to find Android headers/libraries
168+ # CMAKE_SYSROOT is set by the Android NDK toolchain file
169+ if (DEFINED CMAKE_SYSROOT)
170+ list (APPEND COMPILER_COMMAND_LIST "--sysroot=${CMAKE_SYSROOT} " )
171+ else ()
172+ message (WARNING "CMAKE_SYSROOT is not defined. Compiler might not find standard headers/libraries for feature detection." )
173+ endif ()
174+
175+ # Append the architecture flags (e.g., -march=armv8.6-a)
176+ list (APPEND COMPILER_COMMAND_LIST ${ARCH_FLAGS} )
177+
178+ # Append the flags to dump predefined macros
179+ list (APPEND COMPILER_COMMAND_LIST -dM -E -)
180+
156181 execute_process (
157- COMMAND ${CMAKE_C_COMPILER} ${ARCH_FLAGS} -dM -E -
182+ COMMAND ${COMPILER_COMMAND_LIST}
158183 INPUT_FILE ${FEAT_INPUT_FILE}
159184 OUTPUT_VARIABLE ARM_FEATURE
160185 RESULT_VARIABLE ARM_FEATURE_RESULT
161186 )
162187 if (ARM_FEATURE_RESULT)
163188 message (WARNING "Failed to get ARM features" )
164189 else ()
190+ message ("ARM feature result: ${ARM_FEATURE_RESULT} " )
191+
165192 foreach (feature DOTPROD SVE MATMUL_INT8 FMA FP16_VECTOR_ARITHMETIC SME)
166193 string (FIND "${ARM_FEATURE} " "__ARM_FEATURE_${feature} 1" feature_pos)
167194 if (NOT ${feature_pos} EQUAL -1)
168- message (STATUS "ARM feature ${feature} enabled" )
195+ message ("ARM feature ${feature} enabled" )
169196 endif ()
170197 endforeach ()
171198 endif ()
0 commit comments