blob: 772fd7c669ed1790833f76a2923880833d7ff806 [file] [log] [blame]
# 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()