File: GitGetChangesetID.cmake

package info (click to toggle)
openclonk 5.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 95,984 kB
  • ctags: 30,251
  • sloc: cpp: 156,513; ansic: 63,819; xml: 31,289; python: 1,090; php: 767; makefile: 138; ruby: 27; sh: 22
file content (52 lines) | stat: -rwxr-xr-x 1,636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# OpenClonk, http://www.openclonk.org
#
# Copyright (c) 2012-2013, The OpenClonk Team and contributors
#
# Distributed under the terms of the ISC license; see accompanying file
# "COPYING" for details.
#
# "Clonk" is a registered trademark of Matthes Bender, used with permission.
# See accompanying file "TRADEMARK" for details.
#
# To redistribute this file separately, substitute the full license texts
# for the above references.

function(git_get_changeset_id VAR)
	find_package(Git QUIET)
	if (GIT_FOUND)
		execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
			COMMAND "${GIT_EXECUTABLE}" "rev-parse" "HEAD"
			RESULT_VARIABLE GIT_RESULT
			OUTPUT_VARIABLE C4REVISION
			OUTPUT_STRIP_TRAILING_WHITESPACE
			ERROR_QUIET)

		if(GIT_RESULT EQUAL 0)
			string(SUBSTRING "${C4REVISION}" 0 12 C4REVISION)
			execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
				COMMAND "${GIT_EXECUTABLE}" "status" "--porcelain"
				OUTPUT_VARIABLE GIT_STATUS
			)
			string(REGEX MATCH "^[MADRC ][MD ]" WORKDIR_DIRTY "${GIT_STATUS}")
		endif()
	endif()
	if (NOT C4REVISION)
		# Git not found or not a git workdir
		file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.git_archival" C4REVISION
			LIMIT_COUNT 1
			REGEX "node: [0-9a-f]+"
		)
		string(LENGTH "${C4REVISION}" revlength)
		if(revlength LESS 18)
			set(C4REVISION "unknown")
			message(WARNING "Could not retrieve git revision. Please set GIT_EXECUTABLE!")
		else()
			string(SUBSTRING "${C4REVISION}" 6 12 C4REVISION)
		endif()
		unset(revlength)
	endif()
	if(WORKDIR_DIRTY)
		set(C4REVISION "${C4REVISION}+")
	endif()
	set(${VAR} "${C4REVISION}" PARENT_SCOPE)
endfunction()