eive-obsw/cmake/EiveHelpers.cmake
Robin Mueller 2580b7cb20
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
proper handling for git sha hash
2023-02-07 19:37:23 +01:00

32 lines
1.4 KiB
CMake

# Determines the git version with git describe and returns it by setting
# the GIT_INFO list in the parent scope. The list has the following entries
# 1. Full version string
# 2. Major version
# 3. Minor version
# 4. Revision
# 5. (Optional) git SHA hash and commits since tag when applicable
function(determine_version_with_git)
include(GetGitRevisionDescription)
git_describe(VERSION ${ARGN})
string(FIND ${VERSION} "." VALID_VERSION)
if(VALID_VERSION EQUAL -1)
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
return()
endif()
# Parse the version information into pieces.
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" _VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" _VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
set(GIT_INFO ${VERSION})
list(APPEND GIT_INFO ${_VERSION_MAJOR})
list(APPEND GIT_INFO ${_VERSION_MINOR})
list(APPEND GIT_INFO ${_VERSION_PATCH})
if(NOT VERSION_SHA1 STREQUAL VERSION)
list(APPEND GIT_INFO ${VERSION_SHA1})
endif()
set(GIT_INFO ${GIT_INFO} PARENT_SCOPE)
message(STATUS "GIT INFO: ${GIT_INFO}")
message(STATUS "eive | Set git version info into GIT_INFO from the git tag ${VERSION}")
endfunction()