CMakeVersion.cmake 2.7 KB

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