Anas Nashif | 3ae5262 | 2019-04-06 09:08:09 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | |
Marc Herbert | a880fb1 | 2019-05-03 18:29:08 -0700 | [diff] [blame] | 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 | |
Mark Ruvald Pedersen | 55d6b4c | 2018-11-26 23:39:51 +0100 | [diff] [blame] | 13 | |
| 14 | # https://cmake.org/cmake/help/latest/module/FindGit.html |
| 15 | find_package(Git QUIET) |
Torsten Rasmussen | 8ff65f4 | 2021-05-07 11:41:09 +0200 | [diff] [blame] | 16 | if(NOT DEFINED BUILD_VERSION AND GIT_FOUND) |
Marc Herbert | f085647 | 2019-02-20 16:33:30 -0800 | [diff] [blame] | 17 | execute_process( |
Marc Herbert | 4ea66b3 | 2021-05-04 23:08:13 +0000 | [diff] [blame] | 18 | COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always |
Mark Ruvald Pedersen | 55d6b4c | 2018-11-26 23:39:51 +0100 | [diff] [blame] | 19 | 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 Herbert | 654a2f2 | 2021-05-04 22:43:51 +0000 | [diff] [blame] | 27 | message(STATUS "git describe failed: ${stderr}") |
| 28 | elseif(NOT "${stderr}" STREQUAL "") |
| 29 | message(STATUS "git describe warned: ${stderr}") |
Mark Ruvald Pedersen | 55d6b4c | 2018-11-26 23:39:51 +0100 | [diff] [blame] | 30 | endif() |
Mark Ruvald Pedersen | 55d6b4c | 2018-11-26 23:39:51 +0100 | [diff] [blame] | 31 | endif() |