1 # __________________________________________________________________________________ __ _
3 # Obtain version string from git tags via git_describe and parse result into
4 # convenient version variables.
6 # Tags have to be in the format .*([0-9]+)\.([0-9]+)\.([0-9]+)-(.*), as in
7 # 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]+-(.*)" "\\1" VERSION_EXTRA "${GIT_DESCRIPTION}")
38 "([^-]*-g)" "r\\1" VERSION_EXTRA "${VERSION_EXTRA}")
40 "-" "." VERSION_EXTRA "${VERSION_EXTRA}")
42 set(${_gitversionprefix}_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
43 set(${_gitversionprefix}_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
44 set(${_gitversionprefix}_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
45 set(${_gitversionprefix}_EXTRA "${VERSION_EXTRA}" PARENT_SCOPE)
47 set(${_gitversionprefix}
48 "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}" PARENT_SCOPE)