fix error and version info in shallow git clones
Fix `cmake/GitTagVersion.cmake` to not throw errors when in a shallow git clone, or any git clone that has no tags. And when either git or git tag version info is not available, set the version variables to the defaults, which are: ``` VERSION = '2.0.0' REVISION = 'unknown' VERSION_RELEASE = 0 ```
This commit is contained in:
parent
f5379ab806
commit
52439cee0e
|
@ -114,7 +114,10 @@ if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
|||
get_git_head_revision(REFSPEC COMMITHASH)
|
||||
else()
|
||||
message(WARNING "Git not found, cannot set version info")
|
||||
endif()
|
||||
|
||||
# no git or no tags
|
||||
if(NOT VERSION)
|
||||
set(VERSION 2.0.0)
|
||||
set(REVISION "unknown")
|
||||
set(VERSION_RELEASE 0)
|
||||
|
|
|
@ -8,6 +8,11 @@ function(git_version version revision version_release)
|
|||
# get latest version from tag history
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} tag --sort=-creatordate OUTPUT_VARIABLE sorted_tags OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
# if no tags (e.g. shallow clone) do nothing
|
||||
if(NOT sorted_tags)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# convert to list (see: https://public.kitware.com/pipermail/cmake/2007-May/014222.html)
|
||||
string(REGEX REPLACE ";" "\\\\;" sorted_tags "${sorted_tags}")
|
||||
string(REGEX REPLACE "\n" ";" sorted_tags "${sorted_tags}")
|
||||
|
@ -29,6 +34,11 @@ function(git_version version revision version_release)
|
|||
# get the current revision
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} tag "--format=%(align:width=20)%(refname:short)%(end)%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end)" --sort=-creatordate OUTPUT_VARIABLE sorted_tags_refs OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
# if no tags (e.g. shallow clone) do nothing
|
||||
if(NOT sorted_tags_refs)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# convert to list (see: https://public.kitware.com/pipermail/cmake/2007-May/014222.html)
|
||||
string(REGEX REPLACE ";" "\\\\;" sorted_tags_refs "${sorted_tags_refs}")
|
||||
string(REGEX REPLACE "\n" ";" sorted_tags_refs "${sorted_tags_refs}")
|
||||
|
|
Loading…
Reference in New Issue