Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

100 righe
2.9 KiB

  1. # Execute git command and return the output
  2. Function ( GitExecute COMMAND FORCE OUT_RESULT OUT_SUCCESS )
  3. Set ( ${OUT_SUCCESS} 1 PARENT_SCOPE )
  4. Execute_Process ( COMMAND
  5. bash -c "${COMMAND}"
  6. RESULT_VARIABLE
  7. GIT_RET
  8. OUTPUT_VARIABLE
  9. GIT_REV
  10. ERROR_VARIABLE
  11. GIT_ERR )
  12. If ( NOT ${GIT_RET} EQUAL 0
  13. OR NOT "${GIT_ERR}" STREQUAL ""
  14. OR "${GIT_REV}" STREQUAL "" )
  15. If ( FORCE )
  16. Message ( FATAL_ERROR "Unable to execute git command (command=${COMMAND} out=${GIT_REV}; err=${GIT_ERR}; ret=${GIT_RET})" )
  17. Else ( )
  18. Set ( ${OUT_SUCCESS} 0 PARENT_SCOPE )
  19. EndIf ( )
  20. EndIf ( )
  21. Set ( ${OUT_RESULT} "${GIT_REV}" PARENT_SCOPE )
  22. EndFunction ( )
  23. # Get the version by reading the git tag
  24. Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HASH OUT_BEHIND OUT_DIRTY )
  25. If ( NOT EXISTS "${GIT_ROOT}/.git" )
  26. Return ( )
  27. EndIf ( )
  28. # Find the latest git tag
  29. GitExecute ( "git describe --tags --abbrev=1 --match v[0-9].[0-9]* HEAD" False TAG SUCCESS )
  30. If ( NOT ${SUCCESS} )
  31. Return ( )
  32. EndIf ( )
  33. GitExecute ( "git status -s -uall" True DIRTY SUCCESS )
  34. If ( NOT ${SUCCESS} )
  35. Return ( )
  36. EndIf ( )
  37. GitExecute ( "git rev-parse HEAD" True HASH SUCCESS )
  38. If ( NOT ${SUCCESS} )
  39. Return ( )
  40. EndIf ( )
  41. # Split the git revision string
  42. String ( REGEX REPLACE "^v" "" TAG "${TAG}" )
  43. String ( REPLACE "-" ";" SPLIT "${TAG}" )
  44. List ( LENGTH SPLIT COUNT )
  45. If ( ${COUNT} LESS 2 )
  46. Message ( FATAL_ERROR "Unable to split git tag into it's sub components: ${TAG}!" )
  47. EndIf ( )
  48. List ( GET SPLIT 0 VERSION )
  49. List ( GET SPLIT 1 BEHIND )
  50. # Split the version
  51. String ( STRIP "${VERSION}" SPLIT )
  52. String ( REPLACE "." ";" SPLIT "${SPLIT}" )
  53. List ( LENGTH SPLIT COUNT )
  54. If ( ${COUNT} LESS 2 )
  55. Message ( FATAL_ERROR "Unable to split version string: ${VERSION}!" )
  56. EndIf ( )
  57. # major
  58. List ( GET SPLIT 0 TMP )
  59. Set ( ${OUT_MAJOR} ${TMP} PARENT_SCOPE )
  60. # minor
  61. List ( GET SPLIT 1 TMP )
  62. Set ( ${OUT_MINOR} ${TMP} PARENT_SCOPE )
  63. # patch
  64. If ( ${COUNT} GREATER 2 )
  65. List ( GET SPLIT 2 TMP )
  66. Set ( ${OUT_PATCH} ${TMP} PARENT_SCOPE )
  67. EndIf ( )
  68. # build
  69. If ( ${COUNT} GREATER 3 )
  70. List ( GET SPLIT 3 TMP )
  71. Set ( ${OUT_BUILD} ${TMP} PARENT_SCOPE )
  72. EndIf ( )
  73. # hash
  74. String ( STRIP "${HASH}" HASH )
  75. Set ( ${OUT_HASH} ${HASH} PARENT_SCOPE )
  76. # behind
  77. Set ( ${OUT_BEHIND} ${BEHIND} PARENT_SCOPE )
  78. # dirty
  79. If ( DIRTY )
  80. Set ( ${OUT_DIRTY} 1 PARENT_SCOPE )
  81. Else ( )
  82. Set ( ${OUT_DIRTY} 0 PARENT_SCOPE )
  83. EndIf ( )
  84. EndFunction ( )