CMakeVersionSource.cmake 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Try to identify the current development source version.
  2. set(CMAKE_VERSION_SOURCE "")
  3. if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
  4. find_program(GIT_EXECUTABLE NAMES git git.cmd)
  5. mark_as_advanced(GIT_EXECUTABLE)
  6. if(GIT_EXECUTABLE)
  7. execute_process(
  8. COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=7 HEAD
  9. OUTPUT_VARIABLE head
  10. OUTPUT_STRIP_TRAILING_WHITESPACE
  11. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  12. )
  13. if(head)
  14. set(branch "")
  15. execute_process(
  16. COMMAND ${GIT_EXECUTABLE} name-rev HEAD
  17. OUTPUT_VARIABLE branch
  18. OUTPUT_STRIP_TRAILING_WHITESPACE
  19. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  20. )
  21. string(REGEX REPLACE "HEAD " "" branch "${branch}")
  22. set(CMAKE_VERSION_SOURCE "git-${branch}-${head}")
  23. execute_process(
  24. COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
  25. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  26. )
  27. execute_process(
  28. COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
  29. OUTPUT_VARIABLE dirty
  30. OUTPUT_STRIP_TRAILING_WHITESPACE
  31. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  32. )
  33. if(dirty)
  34. set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
  35. endif()
  36. endif()
  37. endif()
  38. elseif(EXISTS ${CMAKE_SOURCE_DIR}/CVS/Repository)
  39. file(READ ${CMAKE_SOURCE_DIR}/CVS/Repository repo)
  40. set(branch "")
  41. if("${repo}" MATCHES "\\.git/")
  42. string(REGEX REPLACE ".*\\.git/([^\r\n]*).*" "-\\1" branch "${repo}")
  43. endif()
  44. set(CMAKE_VERSION_SOURCE "cvs${branch}")
  45. endif()