-
Notifications
You must be signed in to change notification settings - Fork 0
feat: auto-generate version from git tags #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() | ||
|
Comment on lines
+23
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current regex for parsing major, minor, and patch versions ( |
||
|
|
||
| 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better robustness and portability, it's good practice to use CMake's
find_packageto locate Git before attempting to execute it. This ensures that the build system doesn't fail unexpectedly in environments wheregitis not in the defaultPATH, and uses the executable found by CMake's search logic.