Skip to content

Commit

Permalink
Refactor CMakeLists.txt to set project version based on latest git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ak5k committed Jan 3, 2024
1 parent 31730c3 commit 7eb312d
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ cmake_minimum_required(VERSION 3.15)

project(reallm VERSION 0.0.0 LANGUAGES C CXX)

# Find Git
find_package(Git)

# If Git was found
if(GIT_FOUND)
# Get the latest git tag
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_LATEST_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE "[^0-9.]" "" GIT_LATEST_TAG ${GIT_LATEST_TAG})
# Set the project version to the latest git tag
if(NOT "${GIT_LATEST_TAG}" STREQUAL "")
# Set the project version to the latest git tag
string(REGEX REPLACE "[^0-9.]" "" GIT_LATEST_TAG ${GIT_LATEST_TAG})
project(${PROJECT_NAME} VERSION ${GIT_LATEST_TAG} LANGUAGES C CXX)
endif()
endif()
Expand Down

0 comments on commit 7eb312d

Please sign in to comment.