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