GetGitRevisionDescription.cmake.in 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #
  2. # Internal file for GetGitRevisionDescription.cmake
  3. #
  4. # Requires CMake 2.6 or newer (uses the 'function' command)
  5. #
  6. # Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
  7. # http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC
  8. #
  9. # Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version
  10. # 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  11. set(HEAD_HASH)
  12. file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
  13. string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
  14. if(HEAD_CONTENTS MATCHES "ref")
  15. # named branch
  16. string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
  17. if(EXISTS "@GIT_DIR@/${HEAD_REF}")
  18. configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
  19. else()
  20. configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
  21. file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
  22. if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
  23. set(HEAD_HASH "${CMAKE_MATCH_1}")
  24. endif()
  25. endif()
  26. else()
  27. # detached HEAD
  28. configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
  29. endif()
  30. if(NOT HEAD_HASH)
  31. file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
  32. string(STRIP "${HEAD_HASH}" HEAD_HASH)
  33. endif()