Allow external overriding of auto-fetched git hash identifier in cmake

* This is useful if the build doesn't happen within a git checkout and
  you want to pass in the hash anyway, but it also allows adding
  suffixes like -official etc.
This commit is contained in:
baldurk
2017-03-10 13:17:46 +00:00
parent 8f491421f0
commit 248dbfa4a2
+5
View File
@@ -29,6 +29,8 @@ if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "In-source builds not allowed")
endif()
set(BUILD_VERSION_HASH "" CACHE STRING "The current git commit hash, possibly with suffixes to indicate build type")
function(get_git_hash _git_hash)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
@@ -41,6 +43,9 @@ function(get_git_hash _git_hash)
if(NOT GIT_HASH)
set(GIT_HASH "NO_GIT_COMMIT_HASH_DEFINED")
endif()
if(BUILD_VERSION_HASH)
set(GIT_HASH "${BUILD_VERSION_HASH}")
endif()
set(${_git_hash} "${GIT_HASH}" PARENT_SCOPE)
endfunction(get_git_hash)