summaryrefslogtreecommitdiffstats
path: root/Source/CMakeVersion.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-07-25 13:04:52 (GMT)
committerBrad King <brad.king@kitware.com>2019-07-29 15:25:44 (GMT)
commitf7bf08754be661e936d1131b91ca48616cdb9044 (patch)
treeae6b084007af37003220dc65514c70242b8aa566 /Source/CMakeVersion.cmake
parentac48259333b1b5b5a75e0c2d2f8413bbab782a3e (diff)
downloadCMake-f7bf08754be661e936d1131b91ca48616cdb9044.zip
CMake-f7bf08754be661e936d1131b91ca48616cdb9044.tar.gz
CMake-f7bf08754be661e936d1131b91ca48616cdb9044.tar.bz2
CMakeVersion: Provide Git information in non-exact release versions
Our exact release commits have a subject of the form `CMake <version>`. Distinguish development on a release branch in commits after such a version but before the next release by providing Git information.
Diffstat (limited to 'Source/CMakeVersion.cmake')
-rw-r--r--Source/CMakeVersion.cmake31
1 files changed, 22 insertions, 9 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index d3d866e..c576a24 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -34,17 +34,30 @@ if(EXISTS ${CMake_SOURCE_DIR}/.git)
endif()
endif()
-if(NOT CMake_VERSION_IS_RELEASE)
- # Try to identify the current development source version.
+# 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}")
+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}")
+ endif()
+
+ # If this is a work tree, check whether it is dirty.
if(COMMAND _git)
- _git(rev-parse --verify -q --short=4 HEAD)
+ _git(update-index -q --refresh)
+ _git(diff-index --name-only HEAD --)
if(_git_out)
- set(CMake_VERSION "${CMake_VERSION}-g${_git_out}")
- _git(update-index -q --refresh)
- _git(diff-index --name-only HEAD --)
- if(_git_out)
- set(CMake_VERSION_IS_DIRTY 1)
- endif()
+ set(CMake_VERSION_IS_DIRTY 1)
endif()
endif()
endif()