version.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # SPDX-License-Identifier: Apache-2.0
  2. #.rst:
  3. # version.cmake
  4. # -------------
  5. #
  6. # Inputs:
  7. #
  8. # ``*VERSION*`` and other constants set by
  9. # maintainers in ``${ZEPHYR_BASE}/VERSION``
  10. #
  11. # Outputs with examples::
  12. #
  13. # PROJECT_VERSION 1.14.99.07
  14. # KERNEL_VERSION_STRING "1.14.99-extraver"
  15. #
  16. # KERNEL_VERSION_MAJOR 1
  17. # KERNEL_VERSION_MINOR 14
  18. # KERNEL_PATCHLEVEL 99
  19. # KERNELVERSION 0x10E6307
  20. # KERNEL_VERSION_NUMBER 0x10E63
  21. # ZEPHYR_VERSION_CODE 69219
  22. #
  23. # Most outputs are converted to C macros, see ``version.h.in``
  24. #
  25. # See also: independent and more dynamic ``BUILD_VERSION`` in
  26. # ``git.cmake``.
  27. include(${ZEPHYR_BASE}/cmake/hex.cmake)
  28. file(READ ${ZEPHYR_BASE}/VERSION ver)
  29. string(REGEX MATCH "VERSION_MAJOR = ([0-9]*)" _ ${ver})
  30. set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
  31. string(REGEX MATCH "VERSION_MINOR = ([0-9]*)" _ ${ver})
  32. set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1})
  33. string(REGEX MATCH "PATCHLEVEL = ([0-9]*)" _ ${ver})
  34. set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_1})
  35. string(REGEX MATCH "VERSION_TWEAK = ([0-9]*)" _ ${ver})
  36. set(PROJECT_VERSION_TWEAK ${CMAKE_MATCH_1})
  37. string(REGEX MATCH "EXTRAVERSION = ([a-z0-9]*)" _ ${ver})
  38. set(PROJECT_VERSION_EXTRA ${CMAKE_MATCH_1})
  39. # Temporary convenience variable
  40. set(PROJECT_VERSION_WITHOUT_TWEAK ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
  41. if(PROJECT_VERSION_EXTRA)
  42. set(PROJECT_VERSION_EXTRA_STR "-${PROJECT_VERSION_EXTRA}")
  43. endif()
  44. if(PROJECT_VERSION_TWEAK)
  45. set(PROJECT_VERSION ${PROJECT_VERSION_WITHOUT_TWEAK}.${PROJECT_VERSION_TWEAK})
  46. else()
  47. set(PROJECT_VERSION ${PROJECT_VERSION_WITHOUT_TWEAK})
  48. endif()
  49. set(PROJECT_VERSION_STR ${PROJECT_VERSION}${PROJECT_VERSION_EXTRA_STR})
  50. if(DEFINED BUILD_VERSION)
  51. set(BUILD_VERSION_STR ", build: ${BUILD_VERSION}")
  52. endif()
  53. if (NOT NO_PRINT_VERSION)
  54. message(STATUS "Zephyr version: ${PROJECT_VERSION_STR} (${ZEPHYR_BASE})${BUILD_VERSION_STR}")
  55. endif()
  56. set(MAJOR ${PROJECT_VERSION_MAJOR}) # Temporary convenience variable
  57. set(MINOR ${PROJECT_VERSION_MINOR}) # Temporary convenience variable
  58. set(PATCH ${PROJECT_VERSION_PATCH}) # Temporary convenience variable
  59. math(EXPR KERNEL_VERSION_NUMBER_INT "(${MAJOR} << 16) + (${MINOR} << 8) + (${PATCH})")
  60. math(EXPR KERNELVERSION_INT "(${MAJOR} << 24) + (${MINOR} << 16) + (${PATCH} << 8) + (${PROJECT_VERSION_TWEAK})")
  61. to_hex(${KERNEL_VERSION_NUMBER_INT} KERNEL_VERSION_NUMBER)
  62. to_hex(${KERNELVERSION_INT} KERNELVERSION)
  63. set(KERNEL_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
  64. set(KERNEL_VERSION_MINOR ${PROJECT_VERSION_MINOR})
  65. set(KERNEL_PATCHLEVEL ${PROJECT_VERSION_PATCH})
  66. if(PROJECT_VERSION_EXTRA)
  67. set(KERNEL_VERSION_STRING "\"${PROJECT_VERSION_WITHOUT_TWEAK}-${PROJECT_VERSION_EXTRA}\"")
  68. else()
  69. set(KERNEL_VERSION_STRING "\"${PROJECT_VERSION_WITHOUT_TWEAK}\"")
  70. endif()
  71. set(ZEPHYR_VERSION_CODE ${KERNEL_VERSION_NUMBER_INT})
  72. # Cleanup convenience variables
  73. unset(MAJOR)
  74. unset(MINOR)
  75. unset(PATCH)
  76. unset(PROJECT_VERSION_WITHOUT_TWEAK)