Browse Source
Create a CMake git module for a git_describe function. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>pull/77806/head
2 changed files with 40 additions and 17 deletions
@ -0,0 +1,34 @@ |
|||||||
|
# SPDX-License-Identifier: Apache-2.0 |
||||||
|
|
||||||
|
include_guard(GLOBAL) |
||||||
|
|
||||||
|
find_package(Git QUIET) |
||||||
|
|
||||||
|
# Usage: |
||||||
|
# git_describe(<dir> <output>) |
||||||
|
# |
||||||
|
# Helper function to get a short GIT desciption associated with a directory. |
||||||
|
# OUTPUT is set to the output of `git describe --abbrev=12 --always` as run |
||||||
|
# from DIR. |
||||||
|
# |
||||||
|
function(git_describe DIR OUTPUT) |
||||||
|
if(GIT_FOUND) |
||||||
|
execute_process( |
||||||
|
COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always |
||||||
|
WORKING_DIRECTORY ${DIR} |
||||||
|
OUTPUT_VARIABLE DESCRIPTION |
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE |
||||||
|
ERROR_STRIP_TRAILING_WHITESPACE |
||||||
|
ERROR_VARIABLE stderr |
||||||
|
RESULT_VARIABLE return_code |
||||||
|
) |
||||||
|
if(return_code) |
||||||
|
message(STATUS "git describe failed: ${stderr}") |
||||||
|
elseif(NOT "${stderr}" STREQUAL "") |
||||||
|
message(STATUS "git describe warned: ${stderr}") |
||||||
|
else() |
||||||
|
# Save output |
||||||
|
set(${OUTPUT} ${DESCRIPTION} PARENT_SCOPE) |
||||||
|
endif() |
||||||
|
endif() |
||||||
|
endfunction() |
Loading…
Reference in new issue