cmake/Source/CMakeVersion.cmake

85 lines
2.6 KiB
CMake
Raw Normal View History

2012-06-27 20:52:58 +03:00
# CMake version number components.
2014-08-03 19:52:23 +02:00
set(CMake_VERSION_MAJOR 3)
2023-07-02 19:51:09 +02:00
set(CMake_VERSION_MINOR 27)
set(CMake_VERSION_PATCH 0)
2023-07-14 19:10:31 +02:00
set(CMake_VERSION_RC 5)
2020-02-01 23:06:01 +01:00
set(CMake_VERSION_IS_DIRTY 0)
# 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)
2022-11-16 20:14:03 +01:00
string(APPEND CMake_VERSION "-rc${CMake_VERSION_RC}")
2020-02-01 23:06:01 +01:00
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(NOT CMake_VERSION_NO_GIT)
# If this source was exported by 'git archive', use its commit info.
2023-07-14 19:10:31 +02:00
set(git_info [==[8bcba75b1c CMake 3.27.0-rc5]==])
2020-02-01 23:06:01 +01:00
# 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)
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()
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][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}$")
2022-11-16 20:14:03 +01:00
string(APPEND CMake_VERSION "-g${git_hash}")
2020-02-01 23:06:01 +01:00
endif()
# If this is a work tree, check whether it is dirty.
if(COMMAND _git)
_git(update-index -q --refresh)
_git(diff-index --name-only HEAD --)
if(_git_out)
set(CMake_VERSION_IS_DIRTY 1)
endif()
endif()
else()
# No commit information.
if(NOT CMake_VERSION_IS_RELEASE)
# Generic development version.
2022-11-16 20:14:03 +01:00
string(APPEND CMake_VERSION "-git")
2020-02-01 23:06:01 +01:00
endif()
endif()
endif()
# 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_IS_DIRTY)
2022-11-16 20:14:03 +01:00
string(APPEND CMake_VERSION "-dirty")
2020-02-01 23:06:01 +01:00
endif()