diff options
author | Brad King <brad.king@kitware.com> | 2019-10-11 17:43:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-10-11 17:49:59 (GMT) |
commit | b254b0651ef093476322165f919e0a930534473b (patch) | |
tree | 402eaa33f3853a2b3a727001ab990398bd83f28b | |
parent | 9150c818b7d2afb868575fcb2e0c9ba62b9d7f85 (diff) | |
download | CMake-b254b0651ef093476322165f919e0a930534473b.zip CMake-b254b0651ef093476322165f919e0a930534473b.tar.gz CMake-b254b0651ef093476322165f919e0a930534473b.tar.bz2 |
CMakeVersion: Prefer Git information provided by 'git archive' exports
Update the approach from commit fe2c558ba6 (CMakeVersion: Preserve Git
information during 'git archive', 2019-07-25, v3.16.0-rc1~337^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 CMake commit information.
-rw-r--r-- | Source/CMakeVersion.cmake | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 0f2a2d2..092f64d 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -19,7 +19,12 @@ else() set(CMake_VERSION_IS_RELEASE 0) endif() -if(EXISTS ${CMake_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 ${CMake_SOURCE_DIR}/.git) find_package(Git QUIET) if(GIT_FOUND) macro(_git) @@ -32,16 +37,11 @@ if(EXISTS ${CMake_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$]==]) + 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. |