CMakeVersion.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # CMake version number components.
  2. set(CMake_VERSION_MAJOR 3)
  3. set(CMake_VERSION_MINOR 16)
  4. set(CMake_VERSION_PATCH 0)
  5. set(CMake_VERSION_RC 4)
  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(NOT CMake_VERSION_NO_GIT)
  20. # If this source was exported by 'git archive', use its commit info.
  21. set(git_info [==[$Format:%h %s$]==])
  22. # Otherwise, try to identify the current development source version.
  23. if(NOT 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]* "
  24. AND EXISTS ${CMake_SOURCE_DIR}/.git)
  25. find_package(Git QUIET)
  26. if(GIT_FOUND)
  27. macro(_git)
  28. execute_process(
  29. COMMAND ${GIT_EXECUTABLE} ${ARGN}
  30. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  31. RESULT_VARIABLE _git_res
  32. OUTPUT_VARIABLE _git_out OUTPUT_STRIP_TRAILING_WHITESPACE
  33. ERROR_VARIABLE _git_err ERROR_STRIP_TRAILING_WHITESPACE
  34. )
  35. endmacro()
  36. endif()
  37. if(COMMAND _git)
  38. # Get the commit checked out in this work tree.
  39. _git(log -n 1 HEAD "--pretty=format:%h %s" --)
  40. set(git_info "${_git_out}")
  41. endif()
  42. endif()
  43. # Extract commit information if available.
  44. 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]* (.*)$")
  45. # Have commit information.
  46. set(git_hash "${CMAKE_MATCH_1}")
  47. set(git_subject "${CMAKE_MATCH_2}")
  48. # If this is not the exact commit of a release, add dev info.
  49. if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$")
  50. set(CMake_VERSION "${CMake_VERSION}-g${git_hash}")
  51. endif()
  52. # If this is a work tree, check whether it is dirty.
  53. if(COMMAND _git)
  54. _git(update-index -q --refresh)
  55. _git(diff-index --name-only HEAD --)
  56. if(_git_out)
  57. set(CMake_VERSION_IS_DIRTY 1)
  58. endif()
  59. endif()
  60. else()
  61. # No commit information.
  62. if(NOT CMake_VERSION_IS_RELEASE)
  63. # Generic development version.
  64. set(CMake_VERSION "${CMake_VERSION}-git")
  65. endif()
  66. endif()
  67. endif()
  68. # Extract the version suffix component.
  69. if(CMake_VERSION MATCHES "-(.*)$")
  70. set(CMake_VERSION_SUFFIX "${CMAKE_MATCH_1}")
  71. else()
  72. set(CMake_VERSION_SUFFIX "")
  73. endif()
  74. if(CMake_VERSION_IS_DIRTY)
  75. set(CMake_VERSION ${CMake_VERSION}-dirty)
  76. endif()