diff --git a/cmake/version.cmake b/cmake/version.cmake index 5a802b4050bc..24afa098092a 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -1,6 +1,25 @@ + math(EXPR NCS_VERSION_CODE "(${NCS_VERSION_MAJOR} << 16) + (${NCS_VERSION_MINOR} << 8) + (${NCS_VERSION_PATCH})") # to_hex is made available by ${ZEPHYR_BASE}/cmake/hex.cmake to_hex(${NCS_VERSION_CODE} NCS_VERSION_NUMBER) +find_package(Git QUIET) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always + WORKING_DIRECTORY ${ZEPHYR_BASE}/../nrf + OUTPUT_VARIABLE NCS_BUILD_VERSION_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE stderr + RESULT_VARIABLE return_code + ) + if(return_code) + message(STATUS "git describe failed: ${stderr}") + elseif(NOT "${stderr}" STREQUAL "") + message(STATUS "git describe warned: ${stderr}") + endif() +endif() + configure_file(${NRF_DIR}/ncs_version.h.in ${ZEPHYR_BINARY_DIR}/include/generated/ncs_version.h) diff --git a/ncs_version.h.in b/ncs_version.h.in index 19ef2143446b..3f2b990cccf9 100644 --- a/ncs_version.h.in +++ b/ncs_version.h.in @@ -10,4 +10,6 @@ #define NCS_PATCHLEVEL @NCS_VERSION_PATCH@ #define NCS_VERSION_STRING "@NCS_VERSION@" +#define NCS_BUILD_VERSION @NCS_BUILD_VERSION_NAME@ + #endif /* _NCS_VERSION_H_ */