blob: c5bddf87e135462980eaa03917d96294cdb5b784 [file] [log] [blame]
bin.chen1a426d32021-10-13 10:52:36 +08001# SPDX-License-Identifier: Apache-2.0
2
3#.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
13
14# https://cmake.org/cmake/help/latest/module/FindGit.html
15find_package(Git QUIET)
16if(NOT DEFINED BUILD_VERSION AND GIT_FOUND)
17 execute_process(
18 COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always
19 WORKING_DIRECTORY ${SDK_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)
27 message(STATUS "git describe failed: ${stderr}")
28 elseif(NOT "${stderr}" STREQUAL "")
29 message(STATUS "git describe warned: ${stderr}")
30 endif()
31
32 message(STATUS "BUILD_VERSION: ${BUILD_VERSION}")
33endif()