diff --git a/CMakeLists.txt b/CMakeLists.txt index c7d07583..bd09527d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/GitTagVersion.cmake b/cmake/GitTagVersion.cmake index ca484a96..b46e98e3 100644 --- a/cmake/GitTagVersion.cmake +++ b/cmake/GitTagVersion.cmake @@ -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}")