From 5c4ca36c5a27d7dc282ccd63c3beb29856b364c1 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 16 Mar 2026 23:02:56 +0100 Subject: [PATCH] Harmonise passing build version Avoid running some configure step, instead pass it as a define like the Makefile --- src/.gitignore | 2 -- src/CMakeLists.txt | 3 ++- src/version.cpp | 7 ------- 3 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 src/.gitignore diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 889920df..00000000 --- a/src/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Generated by CMake -/.version.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f851bb21..7f911669 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,8 +9,9 @@ add_library(common OBJECT "style.cpp" "usage.cpp" "util.cpp" - "_version.cpp" + "version.cpp" ) +target_compile_definitions(common PRIVATE "BUILD_VERSION_STRING=\"${GIT_REV}\"") find_package(BISON 3.0.0 REQUIRED) set(BISON_FLAGS "-Wall -Dlr.type=ielr") diff --git a/src/version.cpp b/src/version.cpp index 6d5f462c..e64e2060 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -25,13 +25,6 @@ extern "C" { } #endif -// This variable is passed via `-D` from the Makefile, but not from CMake -// (in which `configure_file()` is used on this file to replace some syntax) -#ifndef BUILD_VERSION_STRING - // CMake-specific syntax here - #define BUILD_VERSION_STRING "@GIT_REV@" -#endif - char const *get_package_version_string() { if constexpr (literal_strlen(BUILD_VERSION_STRING) > 0) { return BUILD_VERSION_STRING;