From 1b67c5354878d103cc25173df1dd955e665713d0 Mon Sep 17 00:00:00 2001 From: stone Date: Tue, 31 Mar 2026 17:03:27 +0200 Subject: [PATCH] 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. --- ggml/src/ggml-cpu/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml-cpu/CMakeLists.txt b/ggml/src/ggml-cpu/CMakeLists.txt index beebc476..5a9b25f9 100644 --- a/ggml/src/ggml-cpu/CMakeLists.txt +++ b/ggml/src/ggml-cpu/CMakeLists.txt @@ -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)