cmake: handle missing git or .git/

GetGitRevisionDescription.cmake: we don't need fine-grained failure
modes, we only need "yes" or "no".

fix #1292
This commit is contained in:
Justin M. Keyes 2014-10-15 14:40:18 -04:00
parent 7e57d326f4
commit 92b17e174f
2 changed files with 18 additions and 24 deletions

View File

@ -15,6 +15,9 @@ list(APPEND CMAKE_PREFIX_PATH ${DEPS_INSTALL_DIR})
# Version tokens # Version tokens
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT)
if (NOT NVIM_VERSION_COMMIT)
set(NVIM_VERSION_COMMIT "?")
endif()
set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MAJOR 0)
set(NVIM_VERSION_MINOR 0) set(NVIM_VERSION_MINOR 0)
set(NVIM_VERSION_PATCH 0) set(NVIM_VERSION_PATCH 0)
@ -22,7 +25,9 @@ set(NVIM_VERSION_PRERELEASE "-alpha")
# TODO(justinmk): UTC time would be nice here #1071 # TODO(justinmk): UTC time would be nice here #1071
git_timestamp(GIT_TIMESTAMP) git_timestamp(GIT_TIMESTAMP)
# TODO(justinmk): do not set this for "release" builds #1071 # TODO(justinmk): do not set this for "release" builds #1071
if (GIT_TIMESTAMP)
set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View File

@ -70,8 +70,6 @@ endfunction()
function(get_git_head_revision _refspecvar _hashvar) function(get_git_head_revision _refspecvar _hashvar)
get_git_dir(GIT_DIR) get_git_dir(GIT_DIR)
if(NOT GIT_DIR) if(NOT GIT_DIR)
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return() return()
endif() endif()
@ -96,6 +94,11 @@ function(get_git_head_revision _refspecvar _hashvar)
endfunction() endfunction()
function(git_describe _var) function(git_describe _var)
get_git_dir(GIT_DIR)
if(NOT GIT_DIR)
return()
endif()
if(NOT GIT_FOUND) if(NOT GIT_FOUND)
find_package(Git QUIET) find_package(Git QUIET)
endif() endif()
@ -103,27 +106,13 @@ function(git_describe _var)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return() return()
endif() endif()
get_git_dir(GIT_DIR)
if(NOT GIT_DIR)
set(${_var} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
get_git_head_revision(refspec hash) get_git_head_revision(refspec hash)
if(NOT hash) if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return() return()
endif() endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND execute_process(COMMAND
"${GIT_EXECUTABLE}" "${GIT_EXECUTABLE}"
describe describe
@ -145,18 +134,18 @@ function(git_describe _var)
endfunction() endfunction()
function(git_timestamp _var) function(git_timestamp _var)
get_git_dir(GIT_DIR)
if(NOT GIT_DIR)
return()
endif()
if(NOT GIT_FOUND) if(NOT GIT_FOUND)
find_package(Git QUIET) find_package(Git QUIET)
endif() endif()
if(NOT GIT_FOUND) if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
get_git_dir(GIT_DIR)
if(NOT GIT_DIR)
set(${_var} "GITDIR-NOTFOUND" PARENT_SCOPE)
return() return()
endif() endif()
get_git_head_revision(refspec hash) get_git_head_revision(refspec hash)
if(NOT hash) if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)