From 12281ff6362e73c41652213a93c6727438627862 Mon Sep 17 00:00:00 2001
From: Anonymous <>
Date: Tue, 27 Jan 2026 00:00:00 +0000
Subject: [PATCH 2/6] Move version information into a separate static library. Apply preprocessor definitions carrying version numbers to that library only.

---
 ggml/CMakeLists.txt     |  7 -------
 ggml/src/CMakeLists.txt | 10 +++++++++-
 ggml/src/ggml.c         |  8 --------
 ggml/src/ggml_version.c |  9 +++++++++
 4 files changed, 18 insertions(+), 16 deletions(-)
 create mode 100644 ggml/src/ggml_version.c

diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt
index 0176ca1c..b74f1929 100644
--- a/ggml/CMakeLists.txt
+++ b/ggml/CMakeLists.txt
@@ -392,13 +392,6 @@ write_basic_package_version_file(
     VERSION ${GGML_INSTALL_VERSION}
     COMPATIBILITY SameMajorVersion)
 
-target_compile_definitions(ggml-base PRIVATE
-    GGML_VERSION="${GGML_INSTALL_VERSION}"
-    GGML_COMMIT="${GGML_BUILD_COMMIT}"
-)
-message(STATUS "ggml version: ${GGML_INSTALL_VERSION}")
-message(STATUS "ggml commit:  ${GGML_BUILD_COMMIT}")
-
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml-config.cmake
               ${CMAKE_CURRENT_BINARY_DIR}/ggml-version.cmake
         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ggml)
diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt
index 6192a870..714b9110 100644
--- a/ggml/src/CMakeLists.txt
+++ b/ggml/src/CMakeLists.txt
@@ -230,6 +230,14 @@ set_target_properties(ggml PROPERTIES
     SOVERSION ${GGML_VERSION_MAJOR}
 )
 
+add_library(ggml-version STATIC ggml_version.c)
+target_compile_definitions(ggml-version PRIVATE
+    GGML_VERSION="${GGML_INSTALL_VERSION}"
+    GGML_COMMIT="${GGML_BUILD_COMMIT}"
+)
+message(STATUS "ggml version: ${GGML_INSTALL_VERSION}")
+message(STATUS "ggml commit:  ${GGML_BUILD_COMMIT}")
+
 if (GGML_BACKEND_DIR)
     if (NOT GGML_BACKEND_DL)
         message(FATAL_ERROR "GGML_BACKEND_DIR requires GGML_BACKEND_DL")
@@ -464,7 +472,7 @@ foreach (target ggml-base ggml)
     target_compile_features   (${target} PRIVATE c_std_11 cxx_std_17) # don't bump
 endforeach()
 
-target_link_libraries(ggml-base PRIVATE Threads::Threads)
+target_link_libraries(ggml-base PRIVATE Threads::Threads ggml-version)
 
 find_library(MATH_LIBRARY m)
 if (MATH_LIBRARY)
diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c
index 1725ad16..bfcfebd3 100644
--- a/ggml/src/ggml.c
+++ b/ggml/src/ggml.c
@@ -496,14 +496,6 @@ bool ggml_guid_matches(ggml_guid_t guid_a, ggml_guid_t guid_b) {
     return memcmp(guid_a, guid_b, sizeof(ggml_guid)) == 0;
 }
 
-const char * ggml_version(void) {
-    return GGML_VERSION;
-}
-
-const char * ggml_commit(void) {
-    return GGML_COMMIT;
-}
-
 //
 // timing
 //
diff --git a/ggml/src/ggml_version.c b/ggml/src/ggml_version.c
new file mode 100644
index 00000000..670cd6bb
--- /dev/null
+++ b/ggml/src/ggml_version.c
@@ -0,0 +1,9 @@
+#include <ggml.h>
+
+const char * ggml_version(void) {
+    return GGML_VERSION;
+}
+
+const char * ggml_commit(void) {
+    return GGML_COMMIT;
+}
-- 
2.51.0

