1# SPDX-License-Identifier: Apache-2.0 2 3cmake_minimum_required(VERSION 3.20.0) 4 5if(VERSION_TYPE STREQUAL KERNEL) 6 set(BUILD_VERSION_NAME BUILD_VERSION) 7else() 8 set(BUILD_VERSION_NAME ${VERSION_TYPE}_BUILD_VERSION) 9endif() 10 11if(NOT DEFINED ${BUILD_VERSION_NAME}) 12 cmake_path(GET VERSION_FILE PARENT_PATH work_dir) 13 find_package(Git QUIET) 14 if(GIT_FOUND) 15 execute_process( 16 COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always 17 WORKING_DIRECTORY ${work_dir} 18 OUTPUT_VARIABLE ${BUILD_VERSION_NAME} 19 OUTPUT_STRIP_TRAILING_WHITESPACE 20 ERROR_STRIP_TRAILING_WHITESPACE 21 ERROR_VARIABLE stderr 22 RESULT_VARIABLE return_code 23 ) 24 if(return_code) 25 message(STATUS "git describe failed: ${stderr}") 26 elseif(NOT "${stderr}" STREQUAL "") 27 message(STATUS "git describe warned: ${stderr}") 28 endif() 29 endif() 30endif() 31 32include(${ZEPHYR_BASE}/cmake/modules/version.cmake) 33file(READ ${ZEPHYR_BASE}/version.h.in version_content) 34string(CONFIGURE "${version_content}" version_content) 35string(CONFIGURE "${version_content}" version_content) 36file(WRITE ${OUT_FILE} "${version_content}") 37