2022-09-27 11:43:31 +00:00
|
|
|
find_package(Git)
|
|
|
|
|
|
|
|
# Make basic Git information available as variables. Such data will later be embedded into the build, e.g. for view SYSTEM.BUILD_OPTIONS.
|
|
|
|
if (Git_FOUND)
|
|
|
|
# Commit hash + whether the building workspace was dirty or not
|
|
|
|
execute_process(COMMAND
|
|
|
|
"${GIT_EXECUTABLE}" rev-parse HEAD
|
2023-05-18 15:23:39 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
2022-09-27 11:43:31 +00:00
|
|
|
OUTPUT_VARIABLE GIT_HASH
|
|
|
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
# Branch name
|
|
|
|
execute_process(COMMAND
|
|
|
|
"${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
|
2023-05-18 15:23:39 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
2022-09-27 11:43:31 +00:00
|
|
|
OUTPUT_VARIABLE GIT_BRANCH
|
|
|
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
# Date of the commit
|
|
|
|
SET(ENV{TZ} "UTC")
|
|
|
|
execute_process(COMMAND
|
|
|
|
"${GIT_EXECUTABLE}" log -1 --format=%ad --date=iso-local
|
2023-05-18 15:23:39 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
2022-09-27 11:43:31 +00:00
|
|
|
OUTPUT_VARIABLE GIT_DATE
|
|
|
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
# Subject of the commit
|
|
|
|
execute_process(COMMAND
|
|
|
|
"${GIT_EXECUTABLE}" log -1 --format=%s
|
2023-05-18 15:23:39 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
2022-09-27 11:43:31 +00:00
|
|
|
OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
|
|
|
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2022-09-27 11:46:56 +00:00
|
|
|
message(STATUS "Git HEAD commit hash: ${GIT_HASH}")
|
2022-09-27 11:43:31 +00:00
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} status
|
2023-05-18 15:23:39 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2022-09-27 11:43:31 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Git could not be found.")
|
|
|
|
endif()
|
|
|
|
|