blob: fa79e30a54a4ff9f2e3189f923bc16ded9adeafd [file] [log] [blame]
Anas Nashif3ae52622019-04-06 09:08:09 -04001# SPDX-License-Identifier: Apache-2.0
2
Marc Herberta880fb12019-05-03 18:29:08 -07003#.rst:
4# git.cmake
5# ---------
6# If the user didn't already define BUILD_VERSION then try to initialize
7# it with the output of "git describe". Warn but don't error if
8# everything fails and leave BUILD_VERSION undefined.
9#
10# See also: independent and more static ``KERNEL_VERSION_*`` in
11# ``version.cmake`` and ``kernel_version.h``
12
Mark Ruvald Pedersen55d6b4c2018-11-26 23:39:51 +010013
14# https://cmake.org/cmake/help/latest/module/FindGit.html
15find_package(Git QUIET)
Torsten Rasmussen8ff65f42021-05-07 11:41:09 +020016if(NOT DEFINED BUILD_VERSION AND GIT_FOUND)
Marc Herbertf0856472019-02-20 16:33:30 -080017 execute_process(
Marc Herbert4ea66b32021-05-04 23:08:13 +000018 COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always
Mark Ruvald Pedersen55d6b4c2018-11-26 23:39:51 +010019 WORKING_DIRECTORY ${ZEPHYR_BASE}
20 OUTPUT_VARIABLE BUILD_VERSION
21 OUTPUT_STRIP_TRAILING_WHITESPACE
22 ERROR_STRIP_TRAILING_WHITESPACE
23 ERROR_VARIABLE stderr
24 RESULT_VARIABLE return_code
25 )
26 if(return_code)
Marc Herbert654a2f22021-05-04 22:43:51 +000027 message(STATUS "git describe failed: ${stderr}")
28 elseif(NOT "${stderr}" STREQUAL "")
29 message(STATUS "git describe warned: ${stderr}")
Mark Ruvald Pedersen55d6b4c2018-11-26 23:39:51 +010030 endif()
Mark Ruvald Pedersen55d6b4c2018-11-26 23:39:51 +010031endif()