d4aa27ed1b7e960d101741b642ed3ed724bec5f5
[platform/upstream/cmake.git] / Source / CMakeVersion.cmake
1 # CMake version number components.
2 set(CMake_VERSION_MAJOR 3)
3 set(CMake_VERSION_MINOR 22)
4 set(CMake_VERSION_PATCH 4)
5 #set(CMake_VERSION_RC 0)
6 set(CMake_VERSION_IS_DIRTY 0)
7
8 # Start with the full version number used in tags.  It has no dev info.
9 set(CMake_VERSION
10   "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
11 if(DEFINED CMake_VERSION_RC)
12   set(CMake_VERSION "${CMake_VERSION}-rc${CMake_VERSION_RC}")
13 endif()
14
15 # Releases define a small patch level.
16 if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000)
17   set(CMake_VERSION_IS_RELEASE 1)
18 else()
19   set(CMake_VERSION_IS_RELEASE 0)
20 endif()
21
22 if(NOT CMake_VERSION_NO_GIT)
23   # If this source was exported by 'git archive', use its commit info.
24   set(git_info [==[07d351b535 CMake 3.22.4]==])
25
26   # Otherwise, try to identify the current development source version.
27   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]* "
28       AND EXISTS ${CMake_SOURCE_DIR}/.git)
29     find_package(Git QUIET)
30     if(GIT_FOUND)
31       macro(_git)
32         execute_process(
33           COMMAND ${GIT_EXECUTABLE} ${ARGN}
34           WORKING_DIRECTORY ${CMake_SOURCE_DIR}
35           RESULT_VARIABLE _git_res
36           OUTPUT_VARIABLE _git_out OUTPUT_STRIP_TRAILING_WHITESPACE
37           ERROR_VARIABLE _git_err ERROR_STRIP_TRAILING_WHITESPACE
38           )
39       endmacro()
40     endif()
41     if(COMMAND _git)
42       # Get the commit checked out in this work tree.
43       _git(log -n 1 HEAD "--pretty=format:%h %s" --)
44       set(git_info "${_git_out}")
45     endif()
46   endif()
47
48   # Extract commit information if available.
49   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]* (.*)$")
50     # Have commit information.
51     set(git_hash "${CMAKE_MATCH_1}")
52     set(git_subject "${CMAKE_MATCH_2}")
53
54     # If this is not the exact commit of a release, add dev info.
55     if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$")
56       set(CMake_VERSION "${CMake_VERSION}-g${git_hash}")
57     endif()
58
59     # If this is a work tree, check whether it is dirty.
60     if(COMMAND _git)
61       _git(update-index -q --refresh)
62       _git(diff-index --name-only HEAD --)
63       if(_git_out)
64         set(CMake_VERSION_IS_DIRTY 1)
65       endif()
66     endif()
67   else()
68     # No commit information.
69     if(NOT CMake_VERSION_IS_RELEASE)
70       # Generic development version.
71       set(CMake_VERSION "${CMake_VERSION}-git")
72     endif()
73   endif()
74 endif()
75
76 # Extract the version suffix component.
77 if(CMake_VERSION MATCHES "-(.*)$")
78   set(CMake_VERSION_SUFFIX "${CMAKE_MATCH_1}")
79 else()
80   set(CMake_VERSION_SUFFIX "")
81 endif()
82 if(CMake_VERSION_IS_DIRTY)
83   set(CMake_VERSION ${CMake_VERSION}-dirty)
84 endif()