Commit ac482593 authored by Brad King's avatar Brad King 💬
Browse files

CMakeVersion: Re-order logic to obviate addition of each component

parent 311f232f
......@@ -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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment