Skip to content

Commit 96ba66e

Browse files
committed
feat(CMake): Enhance versioning with Git description
- Added logic to retrieve the Git description for the version string if Git is found. - Updated the version string to include the Git description, improving version tracking and clarity during builds. - Added a status message to display the retrieved Git description during the configuration process.
1 parent 1e485d3 commit 96ba66e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,26 @@ project(rpi-imager LANGUAGES CXX C)
3030
set(IMAGER_VERSION_MAJOR 2)
3131
set(IMAGER_VERSION_MINOR 0)
3232
set(IMAGER_VERSION_PATCH 0)
33+
34+
# Get git description for version string
35+
find_package(Git QUIET)
36+
if(GIT_FOUND)
37+
execute_process(
38+
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
39+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
40+
OUTPUT_VARIABLE GIT_DESCRIBE
41+
OUTPUT_STRIP_TRAILING_WHITESPACE
42+
ERROR_QUIET
43+
)
44+
endif()
45+
46+
# Build version string with git description if available
3347
set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.${IMAGER_VERSION_PATCH}")
48+
if(GIT_DESCRIBE)
49+
set(IMAGER_VERSION_STR "${IMAGER_VERSION_STR}-${GIT_DESCRIBE}")
50+
message(STATUS "Git description: ${GIT_DESCRIBE}")
51+
endif()
52+
3453
set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},${IMAGER_VERSION_PATCH},0")
3554
add_definitions(-DIMAGER_VERSION_STR="${IMAGER_VERSION_STR}")
3655
add_definitions(-DIMAGER_VERSION_CSV=${IMAGER_VERSION_CSV})

0 commit comments

Comments
 (0)