Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
CMake
39 lines
1.1 KiB
CMake
# SPDX-License-Identifier: MIT
|
|
#
|
|
# Writes ${OUT} with the three strings src/build_info.hpp declares. Run both at
|
|
# configure time (so the file exists when add_executable names it) and on every
|
|
# build (so the commit and the timestamp are the ones that produced the binary).
|
|
#
|
|
# Expects: SRC (the source tree), OUT (the .cpp to write), VERSION.
|
|
|
|
set(COMMIT "unknown")
|
|
find_package(Git QUIET)
|
|
if(GIT_FOUND AND EXISTS "${SRC}/.git")
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
|
|
WORKING_DIRECTORY "${SRC}"
|
|
OUTPUT_VARIABLE GIT_OUT
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
ERROR_QUIET
|
|
RESULT_VARIABLE GIT_RC)
|
|
if(GIT_RC EQUAL 0 AND NOT GIT_OUT STREQUAL "")
|
|
set(COMMIT "${GIT_OUT}")
|
|
endif()
|
|
endif()
|
|
|
|
string(TIMESTAMP STAMP "%Y-%m-%d %H:%M UTC" UTC)
|
|
|
|
file(WRITE "${OUT}"
|
|
"// SPDX-License-Identifier: MIT
|
|
// Generated by cmake/write_build_info.cmake. Do not edit, do not commit.
|
|
#include \"build_info.hpp\"
|
|
|
|
namespace udpscope::build_info {
|
|
|
|
const char* const kVersion = \"${VERSION}\";
|
|
const char* const kCommit = \"${COMMIT}\";
|
|
const char* const kTimestamp = \"${STAMP}\";
|
|
|
|
} // namespace udpscope::build_info
|
|
")
|