summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-02-13 19:18:17 (GMT)
committerBrad King <brad.king@kitware.com>2020-02-13 19:20:01 (GMT)
commit0027f7bfcf544d50527a9939b7991f538bb9fd80 (patch)
tree74507940d30ddca5a9f06fcddf9ab6834c85316d
parent606697e3e141526e167eb1c96118faf311b3363d (diff)
downloadCastXML-0027f7bfcf544d50527a9939b7991f538bb9fd80.zip
CastXML-0027f7bfcf544d50527a9939b7991f538bb9fd80.tar.gz
CastXML-0027f7bfcf544d50527a9939b7991f538bb9fd80.tar.bz2
Version: Prefer Git information provided by 'git archive' exports
Update the approach from commit 60dc8284 (Version: Update version scheme to distinguish release and dev versions, 2019-04-11, v0.2.0~2) to prefer `export-subst` information. This will allow exported source trees to be imported into unrelated Git repositories while still using the original upstream CastXML commit information.
-rw-r--r--src/Version.cmake24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/Version.cmake b/src/Version.cmake
index 24c6220..202d0e8 100644
--- a/src/Version.cmake
+++ b/src/Version.cmake
@@ -12,7 +12,12 @@ if(CastXML_VERSION_RC)
set(CastXML_VERSION "${CastXML_VERSION}-rc${CastXML_VERSION_RC}")
endif()
-if(EXISTS ${CastXML_SOURCE_DIR}/.git)
+# If this source was exported by 'git archive', use its commit info.
+set(git_info "$Format:%h %s$")
+
+# 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 ${CastXML_SOURCE_DIR}/.git)
find_package(Git QUIET)
if(GIT_FOUND)
macro(_git)
@@ -25,20 +30,17 @@ if(EXISTS ${CastXML_SOURCE_DIR}/.git)
)
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'.
- set(git_info "$Format:%h %s$")
+ # 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()
endif()
# Extract commit information if available.
-if(git_info MATCHES "^([0-9a-f]+) (.*)$")
+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]* (.*)$")
set(git_hash "${CMAKE_MATCH_1}")
set(git_subject "${CMAKE_MATCH_2}")