From d93018367fbe8c9e891a6cd30b4cc1083b33d250 Mon Sep 17 00:00:00 2001 From: mayor Date: Tue, 10 Mar 2026 15:01:33 -0400 Subject: [PATCH 1/2] feat: auto-generate version from git tags Replaces hardcoded VERSION 1.0.0 in CMakeLists.txt with git describe output. Adds version.hpp.in template that CMake configures at build time. Demo now prints version string on startup. Co-Authored-By: Claude Opus 4.6 --- CMakeLists.txt | 33 +++++++++++++++++++++++++++++- examples/demo/main.cpp | 3 +++ include/soft_render/version.hpp.in | 6 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 include/soft_render/version.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 16724b5..db53a4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,40 @@ cmake_minimum_required(VERSION 3.20) -project(soft_render VERSION 1.0.0 LANGUAGES CXX) +project(soft_render LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +# Version from git tags (e.g. 0.0.2-17-g9f8a5e9 → 0.0.2) +execute_process( + COMMAND git describe --tags --always + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE SR_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) +if(NOT SR_VERSION) + set(SR_VERSION "0.0.0-unknown") +endif() + +string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ver_match "${SR_VERSION}") +if(_ver_match) + set(SR_VERSION_MAJOR ${CMAKE_MATCH_1}) + set(SR_VERSION_MINOR ${CMAKE_MATCH_2}) + set(SR_VERSION_PATCH ${CMAKE_MATCH_3}) +else() + set(SR_VERSION_MAJOR 0) + set(SR_VERSION_MINOR 0) + set(SR_VERSION_PATCH 0) +endif() + +message(STATUS "soft_render version: ${SR_VERSION}") + +configure_file( + ${CMAKE_SOURCE_DIR}/include/soft_render/version.hpp.in + ${CMAKE_BINARY_DIR}/generated/soft_render/version.hpp +) + option(ENABLE_SIMD "Enable SIMD optimizations" ON) option(ENABLE_THREADS "Enable multithreading" ON) @@ -35,6 +65,7 @@ add_library(soft_render STATIC target_include_directories(soft_render PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/generated ) if(ENABLE_SIMD) diff --git a/examples/demo/main.cpp b/examples/demo/main.cpp index 7a2ca34..bcc3fd7 100644 --- a/examples/demo/main.cpp +++ b/examples/demo/main.cpp @@ -1,5 +1,6 @@ #include "soft_render/render/renderer.hpp" #include "soft_render/math/mat4.hpp" +#include "soft_render/version.hpp" #include "obj_loader.hpp" #include #include @@ -12,6 +13,8 @@ using namespace sr::pipeline; static const float PI = 3.14159265358979f; int main(int argc, char** argv) { + std::printf("soft_render %s\n", SR_VERSION); + const int W = 800, H = 600; const int FRAMES = 60; diff --git a/include/soft_render/version.hpp.in b/include/soft_render/version.hpp.in new file mode 100644 index 0000000..f891d8d --- /dev/null +++ b/include/soft_render/version.hpp.in @@ -0,0 +1,6 @@ +#pragma once + +#define SR_VERSION "@SR_VERSION@" +#define SR_VERSION_MAJOR @SR_VERSION_MAJOR@ +#define SR_VERSION_MINOR @SR_VERSION_MINOR@ +#define SR_VERSION_PATCH @SR_VERSION_PATCH@ From 76a5ff08398095ab78223bd3cd89e3036a341a47 Mon Sep 17 00:00:00 2001 From: mayor Date: Tue, 10 Mar 2026 15:08:02 -0400 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20address=20Gemini=20review=20?= =?UTF-8?q?=E2=80=94=20find=5Fpackage(Git)=20and=20v-prefix=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use find_package(Git) with .git dir check for robustness in non-git builds. Handle v-prefixed tags (e.g. v1.2.3) in version regex. Co-Authored-By: Claude Opus 4.6 --- CMakeLists.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db53a4a..7a1a206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,18 +6,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Version from git tags (e.g. 0.0.2-17-g9f8a5e9 → 0.0.2) -execute_process( - COMMAND git describe --tags --always - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE SR_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET -) +find_package(Git QUIET) +if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE SR_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) +endif() if(NOT SR_VERSION) set(SR_VERSION "0.0.0-unknown") endif() -string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ver_match "${SR_VERSION}") +string(REGEX MATCH "^v?([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ver_match "${SR_VERSION}") if(_ver_match) set(SR_VERSION_MAJOR ${CMAKE_MATCH_1}) set(SR_VERSION_MINOR ${CMAKE_MATCH_2})