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