From 6381ee81f60e93d293bbfdca6df263f082868561 Mon Sep 17 00:00:00 2001 From: Anonymous <> Date: Tue, 27 Jan 2026 00:00:00 +0000 Subject: [PATCH 5/6] Got rid of generating `build-info.c` because CMake generates the the C file on each invokation, which causes the object file to be rebuilt, which causes cascading relink, which is slow. Replace `OBJECT` with `STATIC` since `OBJECT` is known to be buggy in CMake and so even is not advertised in the docs. --- common/CMakeLists.txt | 7 ++----- common/build-info.cpp | 6 ++++++ common/build-info.cpp.in | 4 ---- 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 common/build-info.cpp delete mode 100644 common/build-info.cpp.in diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3a78ef03..11ccab24 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,12 +32,9 @@ else() message(WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository.") endif() -set(TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp.in") -set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/build-info.cpp") -configure_file(${TEMPLATE_FILE} ${OUTPUT_FILE}) - set(TARGET build_info) -add_library(${TARGET} OBJECT ${OUTPUT_FILE}) +add_library(${TARGET} STATIC ${CMAKE_CURRENT_BINARY_DIR}/build-info.cpp) +target_compile_definitions(${TARGET} PRIVATE "-DLLAMA_BUILD_NUMBER_MACRO=${LLAMA_BUILD_NUMBER}" "-DLLAMA_BUILD_COMMIT=\"${LLAMA_BUILD_COMMIT}\"" "-DBUILD_COMPILER=\"${BUILD_COMPILER}\"" "-DBUILD_TARGET=\"BUILD_TARGET\"") if (BUILD_SHARED_LIBS) set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() diff --git a/common/build-info.cpp b/common/build-info.cpp new file mode 100644 index 00000000..79a04406 --- /dev/null +++ b/common/build-info.cpp @@ -0,0 +1,6 @@ +#include "common.h" + +int LLAMA_BUILD_NUMBER = LLAMA_BUILD_NUMBER; +char const *LLAMA_COMMIT = LLAMA_BUILD_COMMIT; +char const *LLAMA_COMPILER = BUILD_COMPILER; +char const *LLAMA_BUILD_TARGET = BUILD_TARGET; diff --git a/common/build-info.cpp.in b/common/build-info.cpp.in deleted file mode 100644 index aee9d7ea..00000000 --- a/common/build-info.cpp.in +++ /dev/null @@ -1,4 +0,0 @@ -int LLAMA_BUILD_NUMBER = @LLAMA_BUILD_NUMBER@; -char const *LLAMA_COMMIT = "@LLAMA_BUILD_COMMIT@"; -char const *LLAMA_COMPILER = "@BUILD_COMPILER@"; -char const *LLAMA_BUILD_TARGET = "@BUILD_TARGET@"; -- 2.51.0