From 86b351fd64d5ebbf1ba795ffd60c8f4a8c958613 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 4 Sep 2026 10:28:23 +0200 Subject: [PATCH] ggml : replace compile definitions with version.h.in (#28364) This commit adds a cmake version configuration file to replace the current compile definition solution for the version. The motivation for this change is that I made a mistake and did not take into consideration that the compile definition means that this will become a compiler flag for all sources in the target. This means that when a version update happens that will recompile all sources in the target even if they have not changed. Refs: https://github.com/ggml-org/llama.cpp/pull/28278 --- ggml/CMakeLists.txt | 4 ---- ggml/src/CMakeLists.txt | 4 +++- ggml/src/ggml-version.h.in | 4 ++++ ggml/src/ggml.c | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 ggml/src/ggml-version.h.in diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index 634e18c54..b75506a26 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -404,10 +404,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}") diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt index 96535b49f..947732000 100644 --- a/ggml/src/CMakeLists.txt +++ b/ggml/src/CMakeLists.txt @@ -213,7 +213,9 @@ set_target_properties(ggml-base PROPERTIES SOVERSION ${GGML_VERSION_MAJOR} ) -target_include_directories(ggml-base PRIVATE .) +configure_file(ggml-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/ggml-version.h @ONLY) + +target_include_directories(ggml-base PRIVATE . ${CMAKE_CURRENT_BINARY_DIR}) if (GGML_BACKEND_DL) target_compile_definitions(ggml-base PUBLIC GGML_BACKEND_DL) endif() diff --git a/ggml/src/ggml-version.h.in b/ggml/src/ggml-version.h.in new file mode 100644 index 000000000..37de36297 --- /dev/null +++ b/ggml/src/ggml-version.h.in @@ -0,0 +1,4 @@ +#pragma once + +#define GGML_VERSION "@GGML_VERSION@" +#define GGML_COMMIT "@GGML_BUILD_COMMIT@" diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 2d5fdb7c1..6257cdbe5 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -1,6 +1,7 @@ #define _CRT_SECURE_NO_DEPRECATE // Disables "unsafe" warnings on Windows #define _USE_MATH_DEFINES // For M_PI on MSVC +#include "ggml-version.h" #include "ggml-backend.h" #include "ggml-impl.h" #include "ggml-threading.h"