Don't require a Git repo for CMake.

If running CMake and the source is not in a Git repository, set the
build revision to "unknown" instead of failing to generate build files.
This commit is contained in:
Oliver Hamlet
2015-07-20 20:31:55 +01:00
parent 3ba20ff94d
commit d8e47bfd07
+13 -9
View File
@@ -12,17 +12,21 @@
# the one bundled with GitHub for Windows.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_COMMIT_STRING --tags --long)
include(GetGitRevisionDescription OPTIONAL RESULT_VARIABLE GIT_MODULE_PATH)
IF (NOT GIT_MODULE_PATH MATCHES "NOTFOUND")
get_git_head_revision(GIT_REFSPEC GIT_COMMIT_STRING --tags --long)
IF (GIT_COMMIT_STRING MATCHES "GITDIR-NOTFOUND")
set(GIT_COMMIT_STRING "unknown")
IF (GIT_COMMIT_STRING MATCHES "GITDIR-NOTFOUND")
set(GIT_COMMIT_STRING "unknown")
ELSE ()
# Get a shortened ID. Although knowing the shortest unique string requires Git,
# 8 characters should be a good compromise between chance of ambiguity and length,
# especially since the version numbers would narrow down the range of possibly
# ambiguous commits.
string(SUBSTRING ${GIT_COMMIT_STRING} 0 8 GIT_COMMIT_STRING)
ENDIF ()
ELSE ()
# Get a shortened ID. Although knowing the shortest unique string requires Git,
# 8 characters should be a good compromise between chance of ambiguity and length,
# especially since the version numbers would narrow down the range of possibly
# ambiguous commits.
string(SUBSTRING ${GIT_COMMIT_STRING} 0 8 GIT_COMMIT_STRING)
SET (GIT_COMMIT_STRING "unknown")
ENDIF ()
message(STATUS "Git revision: ${GIT_COMMIT_STRING}")