Warning, /HEPMC_Merger/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:
0004 # ${VERSION} - CMake-compatible version (X.Y.Z or X.Y.Z.N), suitable
0005 # for passing to the project() command.
0006 # ${VERSION}_FULL - Full git-describe string (e.g. 26.06.0-10-ge600dc77d),
0007 # suitable for display / install scripts.
0008 macro(set_git_version VERSION)
0009 if(NOT Git_Found)
0010 find_package(Git)
0011 endif()
0012
0013 if(GIT_EXECUTABLE)
0014 # Generate a git-describe version string from Git repository tags
0015 execute_process(
0016 COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "*.*.*"
0017 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0018 OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
0019 RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
0020 OUTPUT_STRIP_TRAILING_WHITESPACE)
0021 if(NOT GIT_DESCRIBE_ERROR_CODE)
0022 set(${VERSION}_FULL ${GIT_DESCRIBE_VERSION})
0023 endif()
0024 endif()
0025
0026 # Final fallback: Just use a bogus version string that is semantically older
0027 # than anything else and spit out a warning to the developer.
0028 if(NOT DEFINED ${VERSION}_FULL)
0029 set(${VERSION}_FULL "0.0.0-unknown")
0030 message(
0031 WARNING
0032 "Failed to determine VERSION from Git tags. Using default version \"${${VERSION}_FULL}\"."
0033 )
0034 endif()
0035
0036 # Strip a leading "v" (e.g. v1.2.3 -> 1.2.3)
0037 string(REGEX REPLACE "^v" "" _git_version_stripped "${${VERSION}_FULL}")
0038
0039 # Extract only the leading X.Y.Z or X.Y.Z.N numeric part so the result is a
0040 # valid CMake version string that can be passed to project().
0041 string(REGEX MATCH "^([0-9]+\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)" _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()