Debian Codegraph @

builds/cmake/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-2023 Ryan Pavlik <[email protected]> <[email protected]>
8 # http://academic.cleardefinition.com
9 # Iowa State University HCI Graduate Program/VRAC
10 #
11 # Copyright 2009-2012, Iowa State University
12 # Copyright 2011-2023, Contributors
13 # Distributed under the Boost Software License, Version 1.0.
14 # (See accompanying file LICENSE_1_0.txt or copy at
15 # http://www.boost.org/LICENSE_1_0.txt)
16 # SPDX-License-Identifier: BSL-1.0
17
18 set(HEAD_HASH)
19
20 file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
21
22 string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
23 if(HEAD_CONTENTS MATCHES "ref")
24 # named branch
25 string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
26 if(EXISTS "@GIT_DIR@/${HEAD_REF}")
27 configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
28 else()
29 if(EXISTS "@GIT_DIR@/packed-refs")
30 configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs"
31 COPYONLY)
32 file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
33 if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
34 set(HEAD_HASH "${CMAKE_MATCH_1}")
35 endif()
36 endif()
37 endif()
38 else()
39 # detached HEAD
40 configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
41 endif()
42
43 if(NOT HEAD_HASH)
44 file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
45 string(STRIP "${HEAD_HASH}" HEAD_HASH)
46 endif()