Skip to content

Commit

Permalink
Be more robust if neither .git nor .tag file can not be found.
Browse files Browse the repository at this point in the history
Before, cmake was bailing out. Fixes #211
  • Loading branch information
dragotin committed Sep 23, 2023
1 parent 100ca9f commit f93cb22
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ get_git_head_revision(GIT_REFSPEC GIT_SHA1)
# this will work if the tar balls have been properly created
# via git-archive.
if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND")
file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate)
string(REPLACE "\n" "" sha1_candidate ${sha1_candidate})
if (NOT ${sha1_candidate} STREQUAL "$Format:%H$")
message("${sha1_candidate}")
set (GIT_SHA1 "${sha1_candidate}")
if (EXISTS "${CMAKE_SOURCE_DIR}/.tag")
file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate)
string(REPLACE "\n" "" sha1_candidate ${sha1_candidate})
if (NOT ${sha1_candidate} STREQUAL "$Format:%H$")
message("${sha1_candidate}")
set (GIT_SHA1 "${sha1_candidate}")
endif()
else()
set (GIT_SHA1 "unknown")
endif()
endif()

Expand Down

0 comments on commit f93cb22

Please sign in to comment.