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