1*897be3a4Schristos# This module defines the following variables utilizing 2*897be3a4Schristos# git to determine the parent tag. And if found the macro 3*897be3a4Schristos# will attempt to parse them in the github tag fomat 4*897be3a4Schristos# 5*897be3a4Schristos# Useful for auto-versioning in our CMakeLists 6*897be3a4Schristos# 7*897be3a4Schristos# EVENT_GIT___VERSION_MAJOR - Major version. 8*897be3a4Schristos# EVENT_GIT___VERSION_MINOR - Minor version 9*897be3a4Schristos# EVENT_GIT___VERSION_STAGE - Stage version 10*897be3a4Schristos# 11*897be3a4Schristos# Example usage: 12*897be3a4Schristos# 13*897be3a4Schristos# event_fuzzy_version_from_git() 14*897be3a4Schristos# message("Libvent major=${EVENT_GIT___VERSION_MAJOR}") 15*897be3a4Schristos# message(" minor=${EVENT_GIT___VERSION_MINOR}") 16*897be3a4Schristos# message(" patch=${EVENT_GIT___VERSION_PATCH}") 17*897be3a4Schristos# message(" stage=${EVENT_GIT___VERSION_STAGE}") 18*897be3a4Schristos# endif() 19*897be3a4Schristos 20*897be3a4Schristosinclude(FindGit) 21*897be3a4Schristos 22*897be3a4Schristosmacro(event_fuzzy_version_from_git) 23*897be3a4Schristos # set our defaults. 24*897be3a4Schristos set(EVENT_GIT___VERSION_MAJOR 2) 25*897be3a4Schristos set(EVENT_GIT___VERSION_MINOR 1) 26*897be3a4Schristos set(EVENT_GIT___VERSION_PATCH 12) 27*897be3a4Schristos set(EVENT_GIT___VERSION_STAGE "stable") 28*897be3a4Schristos 29*897be3a4Schristos find_package(Git) 30*897be3a4Schristos 31*897be3a4Schristos if (GIT_FOUND) 32*897be3a4Schristos execute_process( 33*897be3a4Schristos COMMAND 34*897be3a4Schristos ${GIT_EXECUTABLE} describe --abbrev=0 --always 35*897be3a4Schristos WORKING_DIRECTORY 36*897be3a4Schristos ${PROJECT_SOURCE_DIR} 37*897be3a4Schristos RESULT_VARIABLE 38*897be3a4Schristos GITRET 39*897be3a4Schristos OUTPUT_VARIABLE 40*897be3a4Schristos GITVERSION 41*897be3a4Schristos OUTPUT_STRIP_TRAILING_WHITESPACE 42*897be3a4Schristos ) 43*897be3a4Schristos 44*897be3a4Schristos string(REGEX REPLACE "[\\._-]" ";" VERSION_LIST "${GITVERSION}") 45*897be3a4Schristos if(VERSION_LIST) 46*897be3a4Schristos list(LENGTH VERSION_LIST VERSION_LIST_LENGTH) 47*897be3a4Schristos endif() 48*897be3a4Schristos 49*897be3a4Schristos if ((GITRET EQUAL 0) AND (VERSION_LIST_LENGTH EQUAL 5)) 50*897be3a4Schristos list(GET VERSION_LIST 1 _MAJOR) 51*897be3a4Schristos list(GET VERSION_LIST 2 _MINOR) 52*897be3a4Schristos list(GET VERSION_LIST 3 _PATCH) 53*897be3a4Schristos list(GET VERSION_LIST 4 _STAGE) 54*897be3a4Schristos 55*897be3a4Schristos set(_DEFAULT_VERSION "${EVENT_GIT___VERSION_MAJOR}.${EVENT_GIT___VERSION_MINOR}.${EVENT_GIT___VERSION_PATCH}-${EVENT_GIT___VERSION_STAGE}") 56*897be3a4Schristos set(_GIT_VERSION "${_MAJOR}.${_MINOR}.${_PATCH}-${_STAGE}") 57*897be3a4Schristos 58*897be3a4Schristos if (${_DEFAULT_VERSION} VERSION_LESS ${_GIT_VERSION}) 59*897be3a4Schristos set(EVENT_GIT___VERSION_MAJOR ${_MAJOR}) 60*897be3a4Schristos set(EVENT_GIT___VERSION_MINOR ${_MINOR}) 61*897be3a4Schristos set(EVENT_GIT___VERSION_PATCH ${_PATCH}) 62*897be3a4Schristos set(EVENT_GIT___VERSION_STAGE ${_STAGE}) 63*897be3a4Schristos endif() 64*897be3a4Schristos endif() 65*897be3a4Schristos endif() 66*897be3a4Schristosendmacro() 67