Debian Codegraph @

cmake/modules/GetGitRevisionDescription.cmake.in

raw
1 #
2 # Internal file for GetGitRevisionDescription.cmake
3 #
4 # Requires CMake 2.6 or newer (uses the 'function' command)
5 #
6 # Original Author:
7 # 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
8 # http://academic.cleardefinition.com
9 # Iowa State University HCI Graduate Program/VRAC
10 #
11 # Copyright Iowa State University 2009-2010.
12 #
13 # SPDX-License-Identifier: BSL-1.0
14 #
15
16 set(HEAD_HASH)
17
18 file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
19
20 string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
21 set(GIT_DIR "@GIT_DIR@")
22 # handle git-worktree
23 if(EXISTS "${GIT_DIR}/commondir")
24 file(READ "${GIT_DIR}/commondir" GIT_DIR_NEW LIMIT 1024)
25 string(STRIP "${GIT_DIR_NEW}" GIT_DIR_NEW)
26 if(NOT IS_ABSOLUTE "${GIT_DIR_NEW}")
27 get_filename_component(GIT_DIR_NEW ${GIT_DIR}/${GIT_DIR_NEW} ABSOLUTE)
28 endif()
29 if(EXISTS "${GIT_DIR_NEW}")
30 set(GIT_DIR "${GIT_DIR_NEW}")
31 endif()
32 endif()
33 if(HEAD_CONTENTS MATCHES "ref")
34 # named branch
35 string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
36 if(EXISTS "${GIT_DIR}/${HEAD_REF}")
37 configure_file("${GIT_DIR}/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
38 elseif(EXISTS "${GIT_DIR}/logs/${HEAD_REF}")
39 configure_file("${GIT_DIR}/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
40 set(HEAD_HASH "${HEAD_REF}")
41 endif()
42 else()
43 # detached HEAD
44 configure_file("${GIT_DIR}/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
45 endif()
46
47 if(NOT HEAD_HASH)
48 file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
49 string(STRIP "${HEAD_HASH}" HEAD_HASH)
50 endif()