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