cmake : avoid duplicate -march=native when already set in CFLAGS

If -march= is already specified via CMAKE_C_FLAGS/CMAKE_CXX_FLAGS or
ARCH_FLAGS, do not append -march=native again. This prevents compiler
warnings about redundant flags and allows users to override the march
target by setting it in their build environment.

Fixes duplicate -march flag in ggml-cpu and ggml-amx backends.
This commit is contained in:
stone 2026-03-31 17:03:27 +02:00
parent c4ca35ee50
commit 1b67c53548
1 changed files with 4 additions and 1 deletions

View File

@ -311,7 +311,10 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
endif()
else ()
if (GGML_NATIVE)
list(APPEND ARCH_FLAGS -march=native)
string(REGEX MATCH "-march=[^ ]+" MARCH_MATCH "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
if(NOT MARCH_MATCH)
list(APPEND ARCH_FLAGS -march=native)
endif()
else ()
if (GGML_SSE42)
list(APPEND ARCH_FLAGS -msse4.2)