Warning, /irt/cmake/git_version.cmake is written in an unsupported language. File is not indexed.
0001 # Determine version from git describe cmake-lint: disable=C0103
0002 #
0003 # Sets two variables in the calling scope: ${VERSION} - CMake-compatible
0004 # version (X.Y.Z or X.Y.Z.N), suitable for passing to the project() command.
0005 # ${VERSION}_FULL - Full git-describe string (e.g. 26.06.0-10-ge600dc77d),
0006 # suitable for display / install scripts.
0007 macro(set_git_version VERSION)
0008 if(NOT Git_Found)
0009 find_package(Git)
0010 endif()
0011
0012 if(GIT_EXECUTABLE)
0013 # Generate a git-describe version string from Git repository tags
0014 execute_process(
0015 COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "*.*.*"
0016 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
0017 OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
0018 RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
0019 OUTPUT_STRIP_TRAILING_WHITESPACE)
0020 if(NOT GIT_DESCRIBE_ERROR_CODE)
0021 set(${VERSION}_FULL ${GIT_DESCRIBE_VERSION})
0022 endif()
0023 endif()
0024
0025 # Final fallback: Just use a bogus version string that is semantically older
0026 # than anything else and spit out a warning to the developer.
0027 if(NOT DEFINED ${VERSION}_FULL)
0028 set(${VERSION}_FULL "0.0.0-unknown")
0029 message(
0030 WARNING
0031 "Failed to determine VERSION from Git tags. Using default version \"${${VERSION}_FULL}\"."
0032 )
0033 endif()
0034
0035 # Strip a leading "v" (e.g. v1.2.3 -> 1.2.3)
0036 string(REGEX REPLACE "^v" "" _git_version_stripped "${${VERSION}_FULL}")
0037
0038 # Extract only the leading X.Y.Z or X.Y.Z.N numeric part so the result is a
0039 # valid CMake version string that can be passed to project().
0040 string(REGEX MATCH "^([0-9]+\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)"
0041 _git_version_clean "${_git_version_stripped}")
0042
0043 if(_git_version_clean)
0044 set(${VERSION} "${_git_version_clean}")
0045 else()
0046 set(${VERSION} "0.0.0")
0047 message(
0048 WARNING
0049 "Could not parse a numeric version from \"${${VERSION}_FULL}\". Falling back to \"${${VERSION}}\"."
0050 )
0051 endif()
0052 unset(_git_version_stripped)
0053 unset(_git_version_clean)
0054 endmacro()