diff --git a/CMakeLists.txt b/CMakeLists.txt index 16724b5..7a1a206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,43 @@ 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) +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 "^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}) + 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 +68,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@