From 3cb87cbbeed58b0e82246ff193ac5cdb7b05ee41 Mon Sep 17 00:00:00 2001 From: Brad King Date: Sun, 21 Jul 2019 20:30:32 -0400 Subject: gitattributes: Do not export any .git paths in git archive We have paths for `.gitattributes` itself, `.gitignore`, and `.github`. None should be exported in source archives. --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 24fd9c2..3854b73 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -.gitattributes export-ignore +.git* export-ignore .hooks* export-ignore # Custom attribute to mark sources as using our C code style. -- cgit v0.12 From 8cf4aec5acc2a3a10abbbbbde17c18d96a97e139 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Jul 2019 20:40:16 -0400 Subject: CMakeVersion.rc: Compute resource components only on Windows --- Source/CMakeLists.txt | 15 +++++++++++++++ Source/CMakeVersionCompute.cmake | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 8117916..efd44f4 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -1159,6 +1159,21 @@ include (${CMake_BINARY_DIR}/Source/LocalUserOptions.cmake OPTIONAL) include (${CMake_SOURCE_DIR}/Source/LocalUserOptions.cmake OPTIONAL) if(WIN32) + # Compute the binary version that appears in the RC file. Version + # components in the RC file are 16-bit integers so we may have to + # split the patch component. + if(CMake_VERSION_PATCH MATCHES "^([0-9]+)([0-9][0-9][0-9][0-9])$") + set(CMake_RCVERSION_YEAR "${CMAKE_MATCH_1}") + set(CMake_RCVERSION_MONTH_DAY "${CMAKE_MATCH_2}") + string(REGEX REPLACE "^0+" "" CMake_RCVERSION_MONTH_DAY "${CMake_RCVERSION_MONTH_DAY}") + set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_RCVERSION_YEAR},${CMake_RCVERSION_MONTH_DAY}) + unset(CMake_RCVERSION_MONTH_DAY) + unset(CMake_RCVERSION_YEAR) + else() + set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_VERSION_PATCH}) + endif() + set(CMake_RCVERSION_STR ${CMake_VERSION}) + # Add Windows executable version information. configure_file("CMakeVersion.rc.in" "CMakeVersion.rc" @ONLY) diff --git a/Source/CMakeVersionCompute.cmake b/Source/CMakeVersionCompute.cmake index 160f470..136851c 100644 --- a/Source/CMakeVersionCompute.cmake +++ b/Source/CMakeVersionCompute.cmake @@ -27,18 +27,3 @@ endif() if(CMake_VERSION_IS_DIRTY) set(CMake_VERSION ${CMake_VERSION}-dirty) endif() - -# Compute the binary version that appears in the RC file. Version -# components in the RC file are 16-bit integers so we may have to -# split the patch component. -if(CMake_VERSION_PATCH MATCHES "^([0-9]+)([0-9][0-9][0-9][0-9])$") - set(CMake_RCVERSION_YEAR "${CMAKE_MATCH_1}") - set(CMake_RCVERSION_MONTH_DAY "${CMAKE_MATCH_2}") - string(REGEX REPLACE "^0+" "" CMake_RCVERSION_MONTH_DAY "${CMake_RCVERSION_MONTH_DAY}") - set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_RCVERSION_YEAR},${CMake_RCVERSION_MONTH_DAY}) - unset(CMake_RCVERSION_MONTH_DAY) - unset(CMake_RCVERSION_YEAR) -else() - set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_VERSION_PATCH}) -endif() -set(CMake_RCVERSION_STR ${CMake_VERSION}) -- cgit v0.12 From ecdf38aa36cfcc897e585ba05fd6f6e738bb5157 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Jul 2019 16:41:29 -0400 Subject: CMakeVersion: Move computation logic to main script --- CMakeLists.txt | 3 +-- Source/CMakeVersion.cmake | 27 +++++++++++++++++++++++++++ Source/CMakeVersionCompute.cmake | 29 ----------------------------- Utilities/Doxygen/CMakeLists.txt | 2 +- Utilities/Sphinx/CMakeLists.txt | 2 +- 5 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 Source/CMakeVersionCompute.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5efa077..75ac8bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -626,8 +626,7 @@ endif() # The main section of the CMakeLists file # #----------------------------------------------------------------------- -# Compute CMake_VERSION, etc. -include(Source/CMakeVersionCompute.cmake) +include(Source/CMakeVersion.cmake) # Include the standard Dart testing module enable_testing() diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index ea3b43a..08d3169 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -3,3 +3,30 @@ set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 15) set(CMake_VERSION_PATCH 20190726) #set(CMake_VERSION_RC 0) + +# Releases define a small patch level. +if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) + set(CMake_VERSION_IS_DIRTY 0) + set(CMake_VERSION_IS_RELEASE 1) + set(CMake_VERSION_SOURCE "") +else() + set(CMake_VERSION_IS_DIRTY 0) # may be set to 1 by CMakeVersionSource + set(CMake_VERSION_IS_RELEASE 0) + include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake) +endif() + +# Compute the full version string. +set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}) +if(CMake_VERSION_SOURCE) + set(CMake_VERSION_SUFFIX "${CMake_VERSION_SOURCE}") +elseif(DEFINED CMake_VERSION_RC) + set(CMake_VERSION_SUFFIX "rc${CMake_VERSION_RC}") +else() + set(CMake_VERSION_SUFFIX "") +endif() +if(CMake_VERSION_SUFFIX) + set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SUFFIX}) +endif() +if(CMake_VERSION_IS_DIRTY) + set(CMake_VERSION ${CMake_VERSION}-dirty) +endif() diff --git a/Source/CMakeVersionCompute.cmake b/Source/CMakeVersionCompute.cmake deleted file mode 100644 index 136851c..0000000 --- a/Source/CMakeVersionCompute.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# Load version number components. -include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake) - -# Releases define a small patch level. -if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) - set(CMake_VERSION_IS_DIRTY 0) - set(CMake_VERSION_IS_RELEASE 1) - set(CMake_VERSION_SOURCE "") -else() - set(CMake_VERSION_IS_DIRTY 0) # may be set to 1 by CMakeVersionSource - set(CMake_VERSION_IS_RELEASE 0) - include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake) -endif() - -# Compute the full version string. -set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}) -if(CMake_VERSION_SOURCE) - set(CMake_VERSION_SUFFIX "${CMake_VERSION_SOURCE}") -elseif(DEFINED CMake_VERSION_RC) - set(CMake_VERSION_SUFFIX "rc${CMake_VERSION_RC}") -else() - set(CMake_VERSION_SUFFIX "") -endif() -if(CMake_VERSION_SUFFIX) - set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SUFFIX}) -endif() -if(CMake_VERSION_IS_DIRTY) - set(CMake_VERSION ${CMake_VERSION}-dirty) -endif() diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index ce4cfaf..f52caed 100644 --- a/Utilities/Doxygen/CMakeLists.txt +++ b/Utilities/Doxygen/CMakeLists.txt @@ -7,7 +7,7 @@ if(NOT CMake_SOURCE_DIR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) - include(${CMake_SOURCE_DIR}/Source/CMakeVersionCompute.cmake) + include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake) include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake) unset(CMAKE_DATA_DIR) unset(CMAKE_DATA_DIR CACHE) diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt index e4e6e05..736a7c0 100644 --- a/Utilities/Sphinx/CMakeLists.txt +++ b/Utilities/Sphinx/CMakeLists.txt @@ -7,7 +7,7 @@ if(NOT CMake_SOURCE_DIR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) - include(${CMake_SOURCE_DIR}/Source/CMakeVersionCompute.cmake) + include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake) include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake) unset(CMAKE_DATA_DIR) unset(CMAKE_DATA_DIR CACHE) -- cgit v0.12 From 564bcb4cb3fa8182308d3501b9b98aee1bf837d1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 23 Jul 2019 16:46:38 -0400 Subject: CMakeVersion: Move git logic to main script --- Source/CMakeVersion.cmake | 33 +++++++++++++++++++++++++++++++-- Source/CMakeVersionSource.cmake | 30 ------------------------------ 2 files changed, 31 insertions(+), 32 deletions(-) delete mode 100644 Source/CMakeVersionSource.cmake diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 08d3169..e406b4c 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -10,9 +10,38 @@ if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) set(CMake_VERSION_IS_RELEASE 1) set(CMake_VERSION_SOURCE "") else() - set(CMake_VERSION_IS_DIRTY 0) # may be set to 1 by CMakeVersionSource + set(CMake_VERSION_IS_DIRTY 0) set(CMake_VERSION_IS_RELEASE 0) - include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake) + # Try to identify the current development source version. + set(CMake_VERSION_SOURCE "") + if(EXISTS ${CMake_SOURCE_DIR}/.git/HEAD) + find_program(GIT_EXECUTABLE NAMES git git.cmd) + mark_as_advanced(GIT_EXECUTABLE) + if(GIT_EXECUTABLE) + 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() + endif() + endif() + endif() endif() # Compute the full version string. diff --git a/Source/CMakeVersionSource.cmake b/Source/CMakeVersionSource.cmake deleted file mode 100644 index 5ea1de3..0000000 --- a/Source/CMakeVersionSource.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Try to identify the current development source version. -set(CMake_VERSION_SOURCE "") -if(EXISTS ${CMake_SOURCE_DIR}/.git/HEAD) - find_program(GIT_EXECUTABLE NAMES git git.cmd) - mark_as_advanced(GIT_EXECUTABLE) - if(GIT_EXECUTABLE) - 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() - endif() - endif() -endif() -- cgit v0.12 From e1e7986c00912a89b644ff60a8e63189f8ba1ac5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 08:23:11 -0400 Subject: CMakeVersion: Consider Git even with just a `.git` file --- Source/CMakeVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index e406b4c..02cf748 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -14,7 +14,7 @@ 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/HEAD) + if(EXISTS ${CMake_SOURCE_DIR}/.git) find_program(GIT_EXECUTABLE NAMES git git.cmd) mark_as_advanced(GIT_EXECUTABLE) if(GIT_EXECUTABLE) -- cgit v0.12 From 74ff80323c23a41b4b311b0cf67d6f5f59034d08 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 08:24:48 -0400 Subject: CMakeVersion: Use FindGit module to find Git We now require at least CMake 3.1 to build, and that has the FindGit module. --- Source/CMakeVersion.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 02cf748..4616dee 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -15,9 +15,8 @@ else() # Try to identify the current development source version. set(CMake_VERSION_SOURCE "") if(EXISTS ${CMake_SOURCE_DIR}/.git) - find_program(GIT_EXECUTABLE NAMES git git.cmd) - mark_as_advanced(GIT_EXECUTABLE) - if(GIT_EXECUTABLE) + find_package(Git QUIET) + if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=4 HEAD OUTPUT_VARIABLE head -- cgit v0.12 From 2f608566b4d19192df2d2213d570692075504b29 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 08:37:11 -0400 Subject: CMakeVersion: Factor git execution into helper macro --- Source/CMakeVersion.cmake | 47 +++++++++++++++++++++++------------------------ 1 file 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() -- cgit v0.12 From 311f232f7a045cd781171c2660ef005fb8074e3d Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 08:39:38 -0400 Subject: CMakeVersion: De-duplicate variable initialization --- Source/CMakeVersion.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index abfacad..d3e734c 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -3,6 +3,8 @@ set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 15) set(CMake_VERSION_PATCH 20190726) #set(CMake_VERSION_RC 0) +set(CMake_VERSION_IS_DIRTY 0) +set(CMake_VERSION_SOURCE "") if(EXISTS ${CMake_SOURCE_DIR}/.git) find_package(Git QUIET) @@ -21,14 +23,10 @@ endif() # Releases define a small patch level. if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) - set(CMake_VERSION_IS_DIRTY 0) set(CMake_VERSION_IS_RELEASE 1) - set(CMake_VERSION_SOURCE "") else() - set(CMake_VERSION_IS_DIRTY 0) set(CMake_VERSION_IS_RELEASE 0) # Try to identify the current development source version. - set(CMake_VERSION_SOURCE "") if(COMMAND _git) _git(rev-parse --verify -q --short=4 HEAD) if(_git_out) -- cgit v0.12 From ac48259333b1b5b5a75e0c2d2f8413bbab782a3e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 08:51:04 -0400 Subject: CMakeVersion: Re-order logic to obviate addition of each component --- Source/CMakeVersion.cmake | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d3e734c..d3d866e 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -4,7 +4,20 @@ set(CMake_VERSION_MINOR 15) set(CMake_VERSION_PATCH 20190726) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) -set(CMake_VERSION_SOURCE "") + +# Start with the full version number used in tags. It has no dev info. +set(CMake_VERSION + "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}") +if(DEFINED CMake_VERSION_RC) + set(CMake_VERSION "${CMake_VERSION}-rc${CMake_VERSION_RC}") +endif() + +# Releases define a small patch level. +if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) + set(CMake_VERSION_IS_RELEASE 1) +else() + set(CMake_VERSION_IS_RELEASE 0) +endif() if(EXISTS ${CMake_SOURCE_DIR}/.git) find_package(Git QUIET) @@ -21,16 +34,12 @@ if(EXISTS ${CMake_SOURCE_DIR}/.git) endif() endif() -# Releases define a small patch level. -if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000) - set(CMake_VERSION_IS_RELEASE 1) -else() - set(CMake_VERSION_IS_RELEASE 0) +if(NOT CMake_VERSION_IS_RELEASE) # Try to identify the current development source version. if(COMMAND _git) _git(rev-parse --verify -q --short=4 HEAD) if(_git_out) - set(CMake_VERSION_SOURCE "g${_git_out}") + set(CMake_VERSION "${CMake_VERSION}-g${_git_out}") _git(update-index -q --refresh) _git(diff-index --name-only HEAD --) if(_git_out) @@ -40,18 +49,12 @@ else() endif() endif() -# Compute the full version string. -set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}) -if(CMake_VERSION_SOURCE) - set(CMake_VERSION_SUFFIX "${CMake_VERSION_SOURCE}") -elseif(DEFINED CMake_VERSION_RC) - set(CMake_VERSION_SUFFIX "rc${CMake_VERSION_RC}") +# Extract the version suffix component. +if(CMake_VERSION MATCHES "-(.*)$") + set(CMake_VERSION_SUFFIX "${CMAKE_MATCH_1}") else() set(CMake_VERSION_SUFFIX "") endif() -if(CMake_VERSION_SUFFIX) - set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SUFFIX}) -endif() if(CMake_VERSION_IS_DIRTY) set(CMake_VERSION ${CMake_VERSION}-dirty) endif() -- cgit v0.12 From f7bf08754be661e936d1131b91ca48616cdb9044 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 09:04:52 -0400 Subject: CMakeVersion: Provide Git information in non-exact release versions Our exact release commits have a subject of the form `CMake `. Distinguish development on a release branch in commits after such a version but before the next release by providing Git information. --- Source/CMakeVersion.cmake | 31 ++++++++++++++++++++++--------- 1 file 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() -- cgit v0.12 From 0505a66cbf6c42ffa3592c9866c5772e7806f5fc Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 09:15:18 -0400 Subject: CMakeVersion: Add generic '-git' suffix when no git info is available --- Source/CMakeVersion.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index c576a24..32a40f9 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -60,6 +60,12 @@ 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] 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() # Extract the version suffix component. -- cgit v0.12 From fe2c558ba66dd6a12cf9289adf692c9a76c71ef4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Jul 2019 09:17:53 -0400 Subject: CMakeVersion: Preserve Git information during 'git archive' Use `export-subst` to get information about the Git commit used to produce an archive. --- Source/.gitattributes | 2 ++ Source/CMakeVersion.cmake | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Source/.gitattributes b/Source/.gitattributes index 7c160cc..d0aedc2 100644 --- a/Source/.gitattributes +++ b/Source/.gitattributes @@ -1,2 +1,4 @@ +CMakeVersion.cmake export-subst + # Do not format third-party sources. /kwsys/** -format.clang-format-6.0 diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 32a40f9..193c14f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -39,6 +39,9 @@ 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$]==]) endif() # Extract commit information if available. -- cgit v0.12