1 # __________________________________________________________________________________ __ _
3 # Obtain version string from git tags via git_describe and parse result into
4 # convenient version variables.
6 # Tags have to match the regex ^[^0-9]*([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9a-zA-Z]+),
7 # as in v1.2.3-rc5, where the expressions in parentheses are interpreted as major,
8 # minor, patch and extra (package release) version numbers.
11 # include(GetGitVersion)
12 # get_git_version(VERSION_VARIABLE_PREFIX [<additional args for git_describe>])
14 # Following variables are set by get_git_version:
15 # VERSION_VARIABLE_PREFIX_MAJOR, VERSION_VARIABLE_PREFIX_MINOR,
16 # VERSION_VARIABLE_PREFIX_PATCH, VERSION_VARIABLE_PREFIX_EXTRA,
17 # VERSION_VARIABLE_PREFIX
19 # "THE BEER-WARE LICENSE" (Revision 42):
20 # <cptiglo@treefish.org> wrote this file. As long as you retain this notice
21 # you can do whatever you want with this stuff. If we meet some day, and you
22 # think this stuff is worth it, you can buy me a beer in return.
23 # __________________________________________________________________________________ __ _
25 function(get_git_version _gitversionprefix)
26 include(GetGitRevisionDescription)
27 git_describe(GIT_DESCRIPTION ${ARGN})
30 "^[^0-9]*([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIPTION}")
32 "^[^0-9]*[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIPTION}")
34 "^[^0-9]*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIPTION}")
36 "^[^0-9]*[0-9]+\\.[0-9]+\\.[0-9]+-([0-9a-zA-Z-]+).*" "\\1" VERSION_EXTRA "${GIT_DESCRIPTION}")
38 "([^-]*-g)" "r\\1" VERSION_EXTRA "${VERSION_EXTRA}")
40 "-" "." VERSION_EXTRA "${VERSION_EXTRA}")
42 set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}")
44 if(NOT "${VERSION}" MATCHES
45 "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9a-zA-Z]+\\.?r?[0-9]*\\.?g?[0-9a-zA-Z]*$")
48 "\nCOULD NOT EXTRACT VALID VERSION STRING FROM git_describe!"
49 "\n git_describe returned: \"${GIT_DESCRIPTION}\""
50 "\n Extracted invalid version string: \"${VERSION}\"\n")
52 endif(NOT "${VERSION}" MATCHES
53 "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9a-zA-Z]+\\.?r?[0-9]*\\.?g?[0-9a-zA-Z]*$")
55 set(${_gitversionprefix} "${VERSION}" PARENT_SCOPE)
56 set(${_gitversionprefix}_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
57 set(${_gitversionprefix}_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
58 set(${_gitversionprefix}_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
59 set(${_gitversionprefix}_EXTRA "${VERSION_EXTRA}" PARENT_SCOPE)