CMakeVersion.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # CMake version number components.
  2. set(CMake_VERSION_MAJOR 3)
  3. set(CMake_VERSION_MINOR 15)
  4. set(CMake_VERSION_PATCH 20190801)
  5. #set(CMake_VERSION_RC 0)
  6. set(CMake_VERSION_IS_DIRTY 0)
  7. # Start with the full version number used in tags. It has no dev info.
  8. set(CMake_VERSION
  9. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  10. if(DEFINED CMake_VERSION_RC)
  11. set(CMake_VERSION "${CMake_VERSION}-rc${CMake_VERSION_RC}")
  12. endif()
  13. # Releases define a small patch level.
  14. if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000)
  15. set(CMake_VERSION_IS_RELEASE 1)
  16. else()
  17. set(CMake_VERSION_IS_RELEASE 0)
  18. endif()
  19. if(EXISTS ${CMake_SOURCE_DIR}/.git)
  20. find_package(Git QUIET)
  21. if(GIT_FOUND)
  22. macro(_git)
  23. execute_process(
  24. COMMAND ${GIT_EXECUTABLE} ${ARGN}
  25. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  26. RESULT_VARIABLE _git_res
  27. OUTPUT_VARIABLE _git_out OUTPUT_STRIP_TRAILING_WHITESPACE
  28. ERROR_VARIABLE _git_err ERROR_STRIP_TRAILING_WHITESPACE
  29. )
  30. endmacro()
  31. endif()
  32. endif()
  33. # Try to identify the current development source version.
  34. if(COMMAND _git)
  35. # Get the commit checked out in this work tree.
  36. _git(log -n 1 HEAD "--pretty=format:%h %s" --)
  37. set(git_info "${_git_out}")
  38. else()
  39. # Get the commit exported by 'git archive'.
  40. set(git_info [==[$Format:%h %s$]==])
  41. endif()
  42. # Extract commit information if available.
  43. if(git_info MATCHES "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]?[0-9a-f]?)[0-9a-f]* (.*)$")
  44. # Have commit information.
  45. set(git_hash "${CMAKE_MATCH_1}")
  46. set(git_subject "${CMAKE_MATCH_2}")
  47. # If this is not the exact commit of a release, add dev info.
  48. if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$")
  49. set(CMake_VERSION "${CMake_VERSION}-g${git_hash}")
  50. endif()
  51. # If this is a work tree, check whether it is dirty.
  52. if(COMMAND _git)
  53. _git(update-index -q --refresh)
  54. _git(diff-index --name-only HEAD --)
  55. if(_git_out)
  56. set(CMake_VERSION_IS_DIRTY 1)
  57. endif()
  58. endif()
  59. else()
  60. # No commit information.
  61. if(NOT CMake_VERSION_IS_RELEASE)
  62. # Generic development version.
  63. set(CMake_VERSION "${CMake_VERSION}-git")
  64. endif()
  65. endif()
  66. # Extract the version suffix component.
  67. if(CMake_VERSION MATCHES "-(.*)$")
  68. set(CMake_VERSION_SUFFIX "${CMAKE_MATCH_1}")
  69. else()
  70. set(CMake_VERSION_SUFFIX "")
  71. endif()
  72. if(CMake_VERSION_IS_DIRTY)
  73. set(CMake_VERSION ${CMake_VERSION}-dirty)
  74. endif()