# __________________________________________________________________________ __ _ # get_git_version: # Obtain version string from git tags via git_describe and parse result into # convenient version variables. # # Tags have to be in the format .*([0-9]+)\.([0-9]+)\.([0-9]+)-(.*), as in # v1.2.3-rc5, where the expressions in parentheses are interpreted as major, # minor, patch and extra (package release) version numbers. # # Usage: # include(GetGitVersion) # get_git_version(VERSION_VARIABLE_PREFIX []) # # Following variables are set by get_git_version: # VERSION_VARIABLE_PREFIX_MAJOR, VERSION_VARIABLE_PREFIX_MINOR, # VERSION_VARIABLE_PREFIX_PATCH, VERSION_VARIABLE_PREFIX_EXTRA, # VERSION_VARIABLE_PREFIX # # "THE BEER-WARE LICENSE" (Revision 42): # wrote this file. As long as you retain this notice # you can do whatever you want with this stuff. If we meet some day, and you # think this stuff is worth it, you can buy me a beer in return. # __________________________________________________________________________ __ _ function(get_git_version _gitversionprefix) include(GetGitRevisionDescription) git_describe(GIT_DESCRIPTION ${ARGN}) string(REGEX REPLACE "^[^0-9]*([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIPTION}") string(REGEX REPLACE "^[^0-9]*[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIPTION}") string(REGEX REPLACE "^[^0-9]*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIPTION}") string(REGEX REPLACE "^[^0-9]*[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_EXTRA "${GIT_DESCRIPTION}") string(REGEX REPLACE "([^-]*-g)" "r\\1" VERSION_EXTRA "${VERSION_EXTRA}") string(REGEX REPLACE "-" "." VERSION_EXTRA "${VERSION_EXTRA}") set(${_gitversionprefix}_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE) set(${_gitversionprefix}_MINOR "${VERSION_MINOR}" PARENT_SCOPE) set(${_gitversionprefix}_PATCH "${VERSION_PATCH}" PARENT_SCOPE) set(${_gitversionprefix}_EXTRA "${VERSION_EXTRA}" PARENT_SCOPE) set(${_gitversionprefix} "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}" PARENT_SCOPE) endfunction()