blob: 9f823252d5cc47d8feca6d3fe369ae9c3c0d687d [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)
Marc Herbert39131dc2019-03-01 18:43:44 -080016if(NOT BUILD_VERSION AND GIT_FOUND)
Marc Herbertf0856472019-02-20 16:33:30 -080017 execute_process(
18 COMMAND ${GIT_EXECUTABLE} describe --abbrev=12
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 Herberta880fb12019-05-03 18:29:08 -070027 message(STATUS "git describe failed: ${stderr};
28 BUILD_VERSION is left undefined")
Mark Ruvald Pedersen55d6b4c2018-11-26 23:39:51 +010029 elseif(CMAKE_VERBOSE_MAKEFILE)
30 message(STATUS "git describe stderr: ${stderr}")
31 endif()
32endif()