Skip to content

LLM inference in C/C++

C++ ggml

llama: fix whole source code rebuilt on each new commit (#28278)

Xuan-Son Nguyend230ddd763ff
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8922dc12ad..221e14f7ff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,12 +52,9 @@ set_target_properties(llama PROPERTIES
MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number
)
-target_compile_definitions(llama PRIVATE
- LLAMA_VERSION="${LLAMA_VERSION}"
- LLAMA_COMMIT="${LLAMA_BUILD_COMMIT}"
-)
+configure_file(llama-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/llama-version.h @ONLY)
-target_include_directories(llama PRIVATE .)
+target_include_directories(llama PRIVATE . ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(llama PUBLIC ../include)
target_compile_features (llama PRIVATE cxx_std_17) # don't bump
diff --git a/src/llama-version.h.in b/src/llama-version.h.in
new file mode 100644
index 0000000000..0e081762cf
--- /dev/null
+++ b/src/llama-version.h.in
@@ -0,0 +1,4 @@
+#pragma once
+
+#define LLAMA_VERSION "@LLAMA_VERSION@"
+#define LLAMA_COMMIT "@LLAMA_BUILD_COMMIT@"
diff --git a/src/llama.cpp b/src/llama.cpp
index 633db658c9..ad8e443882 100644
--- a/src/llama.cpp
+++ b/src/llama.cpp
@@ -1,6 +1,7 @@
#include "llama.h"
#include "llama-impl.h"
+#include "llama-version.h"
#include "llama-chat.h"
#include "llama-context.h"