2019-04-06 21:08:09 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-05-04 09:29:08 +08:00
|
|
|
#.rst:
|
|
|
|
# git.cmake
|
|
|
|
# ---------
|
|
|
|
# If the user didn't already define BUILD_VERSION then try to initialize
|
|
|
|
# it with the output of "git describe". Warn but don't error if
|
|
|
|
# everything fails and leave BUILD_VERSION undefined.
|
|
|
|
#
|
|
|
|
# See also: independent and more static ``KERNEL_VERSION_*`` in
|
|
|
|
# ``version.cmake`` and ``kernel_version.h``
|
|
|
|
|
2018-11-27 06:39:51 +08:00
|
|
|
|
|
|
|
# https://cmake.org/cmake/help/latest/module/FindGit.html
|
|
|
|
find_package(Git QUIET)
|
2019-03-02 10:43:44 +08:00
|
|
|
if(NOT BUILD_VERSION AND GIT_FOUND)
|
2019-02-21 08:33:30 +08:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} describe --abbrev=12
|
2018-11-27 06:39:51 +08:00
|
|
|
WORKING_DIRECTORY ${ZEPHYR_BASE}
|
|
|
|
OUTPUT_VARIABLE BUILD_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_VARIABLE stderr
|
|
|
|
RESULT_VARIABLE return_code
|
|
|
|
)
|
|
|
|
if(return_code)
|
2021-05-05 06:43:51 +08:00
|
|
|
message(STATUS "git describe failed: ${stderr}")
|
|
|
|
elseif(NOT "${stderr}" STREQUAL "")
|
|
|
|
message(STATUS "git describe warned: ${stderr}")
|
2018-11-27 06:39:51 +08:00
|
|
|
endif()
|
2021-05-05 06:43:51 +08:00
|
|
|
message(STATUS "BUILD_VERSION=${BUILD_VERSION}")
|
2018-11-27 06:39:51 +08:00
|
|
|
endif()
|