summaryrefslogtreecommitdiffstats
path: root/Source/CMakeVersion.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-10-12 14:29:10 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-10-12 14:29:19 (GMT)
commit07d15d70d2dcb74a2b53e4550cbde2e46dcdc266 (patch)
treedabfbbe43998641f66d3de27eb4ddd8e15ed33ff /Source/CMakeVersion.cmake
parent0a52bada333ca968f6eef36076fe2df3f5cef051 (diff)
parent874396a30d8dc85d45176de4ec53dc951179010e (diff)
downloadCMake-07d15d70d2dcb74a2b53e4550cbde2e46dcdc266.zip
CMake-07d15d70d2dcb74a2b53e4550cbde2e46dcdc266.tar.gz
CMake-07d15d70d2dcb74a2b53e4550cbde2e46dcdc266.tar.bz2
Merge topic 'no-git-version'
874396a30d CMakeVersion: Add option to disable Git suffix b254b0651e CMakeVersion: Prefer Git information provided by 'git archive' exports Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3910
Diffstat (limited to 'Source/CMakeVersion.cmake')
-rw-r--r--Source/CMakeVersion.cmake90
1 files changed, 46 insertions, 44 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 5670622..d6afa4b 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -19,55 +19,57 @@ else()
set(CMake_VERSION_IS_RELEASE 0)
endif()
-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()
-
-# Try to identify the current development source version.
-if(COMMAND _git)
- # Get the commit checked out in this work tree.
- _git(log -n 1 HEAD "--pretty=format:%h %s" --)
- set(git_info "${_git_out}")
-else()
- # Get the commit exported by 'git archive'.
+if(NOT CMake_VERSION_NO_GIT)
+ # If this source was exported by 'git archive', use its commit info.
set(git_info [==[$Format:%h %s$]==])
-endif()
-
-# Extract commit information if available.
-if(git_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]?[0-9a-f]?)[0-9a-f]* (.*)$")
- # Have commit information.
- set(git_hash "${CMAKE_MATCH_1}")
- set(git_subject "${CMAKE_MATCH_2}")
- # If this is not the exact commit of a release, add dev info.
- if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$")
- set(CMake_VERSION "${CMake_VERSION}-g${git_hash}")
+ # Otherwise, try to identify the current development source version.
+ if(NOT git_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]?[0-9a-f]?)[0-9a-f]* "
+ AND 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()
+ if(COMMAND _git)
+ # Get the commit checked out in this work tree.
+ _git(log -n 1 HEAD "--pretty=format:%h %s" --)
+ set(git_info "${_git_out}")
+ endif()
endif()
- # If this is a work tree, check whether it is dirty.
- if(COMMAND _git)
- _git(update-index -q --refresh)
- _git(diff-index --name-only HEAD --)
- if(_git_out)
- set(CMake_VERSION_IS_DIRTY 1)
+ # Extract commit information if available.
+ if(git_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]?[0-9a-f]?)[0-9a-f]* (.*)$")
+ # Have commit information.
+ set(git_hash "${CMAKE_MATCH_1}")
+ set(git_subject "${CMAKE_MATCH_2}")
+
+ # If this is not the exact commit of a release, add dev info.
+ if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$")
+ set(CMake_VERSION "${CMake_VERSION}-g${git_hash}")
+ endif()
+
+ # If this is a work tree, check whether it is dirty.
+ if(COMMAND _git)
+ _git(update-index -q --refresh)
+ _git(diff-index --name-only HEAD --)
+ if(_git_out)
+ set(CMake_VERSION_IS_DIRTY 1)
+ endif()
+ endif()
+ else()
+ # No commit information.
+ if(NOT CMake_VERSION_IS_RELEASE)
+ # Generic development version.
+ set(CMake_VERSION "${CMake_VERSION}-git")
endif()
- endif()
-else()
- # No commit information.
- if(NOT CMake_VERSION_IS_RELEASE)
- # Generic development version.
- set(CMake_VERSION "${CMake_VERSION}-git")
endif()
endif()