GetUrhoRevision.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (c) 2008-2022 the Urho3D project
  2. # License: MIT
  3. # Get Urho3D library revision number
  4. # Use the same commit-ish used by CI server to describe the repository
  5. if (DEFINED ENV{TRAVIS_COMMIT})
  6. set (ARG $ENV{TRAVIS_COMMIT})
  7. elseif (DEFINED ENV{APPVEYOR})
  8. set (ARG $ENV{APPVEYOR_REPO_COMMIT})
  9. else ()
  10. set (ARG --dirty)
  11. endif ()
  12. execute_process (COMMAND git describe ${ARG} RESULT_VARIABLE GIT_EXIT_CODE OUTPUT_VARIABLE LIB_REVISION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  13. if (NOT GIT_EXIT_CODE EQUAL 0)
  14. # No GIT command line tool or not a GIT repository
  15. set (LIB_REVISION Unversioned)
  16. endif ()
  17. if (FILENAME)
  18. # Output complete revision number to a file
  19. file (WRITE ${FILENAME} "const char* revision=\"${LIB_REVISION}\";\n")
  20. else ()
  21. # Output just major.minor.patch number to stdout
  22. string (REGEX MATCH "[^.]+\\.[^-]+" VERSION ${LIB_REVISION}) # Assume release tag always has major.minor format with possible pre-release identifier
  23. if (VERSION)
  24. string (REGEX MATCH "${VERSION}-([A-Z]+)" PRE_ID ${LIB_REVISION}) # Workaround as CMake's regex does not support look around
  25. if (PRE_ID)
  26. set (VERSION ${VERSION}-${CMAKE_MATCH_1})
  27. endif ()
  28. string (REGEX MATCH "${VERSION}-([^-]+)" PATCH ${LIB_REVISION}) # Subsequent commits count after a release tag is treated as patch number
  29. if (PATCH)
  30. set (VERSION ${VERSION}.${CMAKE_MATCH_1})
  31. else ()
  32. set (VERSION ${VERSION}.0)
  33. endif ()
  34. else ()
  35. set (VERSION 0.0.0)
  36. endif ()
  37. execute_process (COMMAND ${CMAKE_COMMAND} -E echo ${VERSION})
  38. endif ()