Commit e14a77971 for llama.cpp

commit e14a779719652200cec7ad58dfa4820edc347182
Author: Xuan-Son Nguyen <son@huggingface.co>
Date:   Fri Nov 6 00:16:13 2026 +0100

    mtmd: enable cmake unity build (#31760)

diff --git a/tools/mtmd/CMakeLists.txt b/tools/mtmd/CMakeLists.txt
index fc9f0bb34..d92340f6b 100644
--- a/tools/mtmd/CMakeLists.txt
+++ b/tools/mtmd/CMakeLists.txt
@@ -12,21 +12,25 @@ endif()

 find_package(Threads REQUIRED)

+set(MTMD_CORE_SOURCES
+    mtmd.cpp
+    mtmd-audio.cpp
+    mtmd-image.cpp
+    mtmd.h
+    mtmd-internal.h
+    mtmd-helper.cpp
+    mtmd-helper-gen.cpp
+    mtmd-helper-common.h
+    mtmd-helper.h
+    clip.cpp
+    clip.h
+    clip-impl.h
+    clip-model.h
+    clip-graph.h
+)
+
 add_library(mtmd
-            mtmd.cpp
-            mtmd-audio.cpp
-            mtmd-image.cpp
-            mtmd.h
-            mtmd-internal.h
-            mtmd-helper.cpp
-            mtmd-helper-gen.cpp
-            mtmd-helper-common.h
-            mtmd-helper.h
-            clip.cpp
-            clip.h
-            clip-impl.h
-            clip-model.h
-            clip-graph.h
+            ${MTMD_CORE_SOURCES}
             models/models.h
             models/chatterbox-gen.cpp
             models/chatterbox-spkenc.cpp
@@ -91,13 +95,22 @@ set_target_properties(mtmd PROPERTIES
     VERSION ${LLAMA_VERSION_BASE}
     SOVERSION ${LLAMA_VERSION_MAJOR}
     MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number
+    UNITY_BUILD ON
+    UNITY_BUILD_BATCH_SIZE 16
 )

+# exclude non-model sources from unity build
+set_source_files_properties(${MTMD_CORE_SOURCES}
+    PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
+
 target_link_libraries     (mtmd PUBLIC ggml llama)
 target_link_libraries     (mtmd PRIVATE Threads::Threads vendor::hash vendor::miniaudio vendor::stb vendor::sheredom)
 target_include_directories(mtmd PUBLIC  .)
 target_compile_features   (mtmd PRIVATE cxx_std_17)

+# for M_PI, set here because a unity batch can include <cmath> before the source that needs it
+target_compile_definitions(mtmd PRIVATE _USE_MATH_DEFINES)
+
 if (MTMD_VIDEO)
     target_compile_definitions(mtmd PRIVATE MTMD_VIDEO)
 endif()
diff --git a/tools/mtmd/clip.cpp b/tools/mtmd/clip.cpp
index a5ab432bb..d4e0fc901 100644
--- a/tools/mtmd/clip.cpp
+++ b/tools/mtmd/clip.cpp
@@ -1,4 +1,3 @@
-#define _USE_MATH_DEFINES // for M_PI
 #include "clip.h"
 #include "clip-impl.h"
 #include "clip-model.h"
diff --git a/tools/mtmd/models/chatterbox-gen.cpp b/tools/mtmd/models/chatterbox-gen.cpp
index d4c4f77bf..00a9a8d81 100644
--- a/tools/mtmd/models/chatterbox-gen.cpp
+++ b/tools/mtmd/models/chatterbox-gen.cpp
@@ -1,4 +1,3 @@
-#define _USE_MATH_DEFINES // for M_PI
 #include "models.h"

 // Chatterbox generation graphs: flow encoder, cfm estimator, s3 tokenizer and hift vocoder
diff --git a/tools/mtmd/mtmd-audio.cpp b/tools/mtmd/mtmd-audio.cpp
index 74d265526..9e60d9697 100644
--- a/tools/mtmd/mtmd-audio.cpp
+++ b/tools/mtmd/mtmd-audio.cpp
@@ -1,6 +1,5 @@
 #include "mtmd-audio.h"

-#define _USE_MATH_DEFINES // for M_PI
 #include <cfloat>
 #include <cmath>
 #include <cstdint>