diff options
author | Brad King <brad.king@kitware.com> | 2019-07-25 12:37:11 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-29 15:25:44 (GMT) |
commit | 2f608566b4d19192df2d2213d570692075504b29 (patch) | |
tree | c66771d72c5c3c5bf8e2fff454320c13f0f6c3e0 /Source | |
parent | 74ff80323c23a41b4b311b0cf67d6f5f59034d08 (diff) | |
download | CMake-2f608566b4d19192df2d2213d570692075504b29.zip CMake-2f608566b4d19192df2d2213d570692075504b29.tar.gz CMake-2f608566b4d19192df2d2213d570692075504b29.tar.bz2 |
CMakeVersion: Factor git execution into helper macro
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeVersion.cmake | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 4616dee..abfacad 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -4,6 +4,21 @@ set(CMake_VERSION_MINOR 15) set(CMake_VERSION_PATCH 20190726) #set(CMake_VERSION_RC 0) +if(EXISTS ${CMake_SOURCE_DIR}/.git) + find_package(Git QUIET) + if(GIT_FOUND) + macro(_git) + execute_process( + COMMAND ${GIT_EXECUTABLE} ${ARGN} + WORKING_DIRECTORY ${CMake_SOURCE_DIR} + RESULT_VARIABLE _git_res + OUTPUT_VARIABLE _git_out OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _git_err ERROR_STRIP_TRAILING_WHITESPACE + ) + endmacro() + endif() +endif() + # Releases define a small patch level. if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) set(CMake_VERSION_IS_DIRTY 0) @@ -14,30 +29,14 @@ else() set(CMake_VERSION_IS_RELEASE 0) # Try to identify the current development source version. set(CMake_VERSION_SOURCE "") - if(EXISTS ${CMake_SOURCE_DIR}/.git) - find_package(Git QUIET) - if(GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=4 HEAD - OUTPUT_VARIABLE head - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMake_SOURCE_DIR} - ) - if(head) - set(CMake_VERSION_SOURCE "g${head}") - execute_process( - COMMAND ${GIT_EXECUTABLE} update-index -q --refresh - WORKING_DIRECTORY ${CMake_SOURCE_DIR} - ) - execute_process( - COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD -- - OUTPUT_VARIABLE dirty - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMake_SOURCE_DIR} - ) - if(dirty) - set(CMake_VERSION_IS_DIRTY 1) - endif() + if(COMMAND _git) + _git(rev-parse --verify -q --short=4 HEAD) + if(_git_out) + set(CMake_VERSION_SOURCE "g${_git_out}") + _git(update-index -q --refresh) + _git(diff-index --name-only HEAD --) + if(_git_out) + set(CMake_VERSION_IS_DIRTY 1) endif() endif() endif() |