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) |
Marc Herbert | 39131dc | 2019-03-01 18:43:44 -0800 | [diff] [blame] | 16 | if(NOT BUILD_VERSION AND GIT_FOUND) |
Marc Herbert | f085647 | 2019-02-20 16:33:30 -0800 | [diff] [blame] | 17 | execute_process( |
| 18 | COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 |
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 | a880fb1 | 2019-05-03 18:29:08 -0700 | [diff] [blame] | 27 | message(STATUS "git describe failed: ${stderr}; |
| 28 | BUILD_VERSION is left undefined") |
Mark Ruvald Pedersen | 55d6b4c | 2018-11-26 23:39:51 +0100 | [diff] [blame] | 29 | elseif(CMAKE_VERBOSE_MAKEFILE) |
| 30 | message(STATUS "git describe stderr: ${stderr}") |
| 31 | endif() |
| 32 | endif() |