ProjectVersion.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #
  2. # This file is responsible for setting the following variables:
  3. #
  4. # ~~~
  5. # BUILD_NUMBER (1035)
  6. # PROJECT_VERSION (4.0.3)
  7. # PROJECT_VERSION_FULL (4.0.3-BETA+1035.PR111.B4)
  8. # PROJECT_VERSION_SUFFIX (-BETA+1035.PR111.B4)
  9. # PROJECT_VERSION_SUFFIX_SHORT (+1035)
  10. #
  11. # The `PROJECT_VERSION` variable is set as soon as the file is included.
  12. # To set the rest, the function `resolve_version_variables` has to be called.
  13. #
  14. # ~~~
  15. FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/Configuration.h CFG_VER_DATA REGEX "#define FW_[A-Z]+ ([0-9]+)" )
  16. LIST(GET CFG_VER_DATA 0 PROJECT_VERSION_MAJOR)
  17. LIST(GET CFG_VER_DATA 1 PROJECT_VERSION_MINOR)
  18. LIST(GET CFG_VER_DATA 2 PROJECT_VERSION_REV)
  19. STRING(REGEX MATCH "FW_MAJOR ([0-9]+)" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  20. SET(PROJECT_VERSION_MAJOR "${CMAKE_MATCH_1}")
  21. STRING(REGEX MATCH "FW_MINOR ([0-9]+)" PROJECT_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  22. SET(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1})
  23. STRING(REGEX MATCH "FW_REVISION +([0-9]+)" PROJECT_VERSION_REV "${PROJECT_VERSION_REV}")
  24. SET(PROJECT_VERSION_REV ${CMAKE_MATCH_1})
  25. SET(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}")
  26. SET(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}" PARENT_SCOPE)
  27. function(resolve_version_variables)
  28. # BUILD_NUMBER
  29. if(NOT BUILD_NUMBER)
  30. git_count_parent_commits(BUILD_NUMBER)
  31. set(ERRORS "GIT-NOTFOUND" "HEAD-HASH-NOTFOUND")
  32. if(BUILD_NUMBER IN_LIST ERRORS)
  33. message(WARNING "Failed to resolve build number: ${BUILD_NUMBER}. Setting to zero.")
  34. set(BUILD_NUMBER "0")
  35. endif()
  36. set(BUILD_NUMBER
  37. ${BUILD_NUMBER}
  38. PARENT_SCOPE
  39. )
  40. endif()
  41. # PROJECT_VERSION_SUFFIX
  42. if(PROJECT_VERSION_SUFFIX STREQUAL "<auto>")
  43. # TODO: set to +<sha>.dirty?.debug?
  44. set(PROJECT_VERSION_SUFFIX "+${BUILD_NUMBER}.LOCAL")
  45. set(PROJECT_VERSION_SUFFIX
  46. "+${BUILD_NUMBER}.LOCAL"
  47. PARENT_SCOPE
  48. )
  49. endif()
  50. # PROJECT_VERSION_SUFFIX_SHORT
  51. if(PROJECT_VERSION_SUFFIX_SHORT STREQUAL "<auto>")
  52. set(PROJECT_VERSION_SUFFIX_SHORT
  53. "+${BUILD_NUMBER}"
  54. PARENT_SCOPE
  55. )
  56. endif()
  57. # PROJECT_VERSION_FULL
  58. set(PROJECT_VERSION_FULL
  59. "${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX}"
  60. PARENT_SCOPE
  61. )
  62. endfunction()