GetGitRevisionDescription.cmake.in 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 2009-2012, Iowa State University
  12. # Copyright 2011-2015, 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. set(HEAD_HASH)
  18. file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
  19. string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
  20. if(HEAD_CONTENTS MATCHES "ref")
  21. # named branch
  22. string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
  23. if(EXISTS "@GIT_DIR@/${HEAD_REF}")
  24. configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
  25. elseif(EXISTS "@GIT_DIR@/packed-refs")
  26. configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
  27. file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
  28. if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
  29. set(HEAD_HASH "${CMAKE_MATCH_1}")
  30. endif()
  31. elseif(EXISTS "@GIT_DIR@/reftable/tables.list")
  32. configure_file("@GIT_DIR@/reftable/tables.list" "@GIT_DATA@/reftable-tables.list" COPYONLY)
  33. endif()
  34. else()
  35. # detached HEAD
  36. configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
  37. endif()
  38. if(NOT HEAD_HASH AND EXISTS "@GIT_DATA@/head-ref")
  39. file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
  40. string(STRIP "${HEAD_HASH}" HEAD_HASH)
  41. endif()