xref: /libbtbb/cmake/set_release.cmake (revision 01a5fc3d2c296bde80cfffd6ebe24c807d54afad)
1# This script controls the version string that is passed at compile time.
2# To override the version, use cmake -DRELEASE_STRING="you_version"
3# If RELEASE_STRING is not explicitly set we attempt to use the latest git
4# commit.  If cmake isn't being run from within a git repository we use the
5# LATEST_RELEASE variable, which developers should set before a release is
6# tagged
7
8if(NOT DEFINED RELEASE_STRING)
9	set(LATEST_RELEASE "2020-12-R1")
10
11	execute_process(
12		COMMAND git log -n 1 --format=%h
13		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
14		RESULT_VARIABLE GIT_EXIT_ERROR
15		ERROR_QUIET
16		OUTPUT_VARIABLE GIT_VERSION
17		OUTPUT_STRIP_TRAILING_WHITESPACE
18	)
19	if (GIT_EXIT_ERROR)
20		# We're probably not in a git repo
21		set(RELEASE_STRING ${LATEST_RELEASE})
22	else (GIT_EXIT_ERROR)
23		# We're in a git repo
24		execute_process(
25			COMMAND git status -s --untracked-files=no
26			OUTPUT_VARIABLE DIRTY
27		)
28		if ( NOT "${DIRTY}" STREQUAL "" )
29			set(DIRTY_FLAG "*")
30		else()
31			set(DIRTY_FLAG "")
32		endif()
33		set(RELEASE_STRING "git-${GIT_VERSION}${DIRTY_FLAG}")
34	endif (GIT_EXIT_ERROR)
35endif(NOT DEFINED RELEASE_STRING)
36