-
Notifications
You must be signed in to change notification settings - Fork 52
/
CompilationInfo.cmake
32 lines (27 loc) · 1.34 KB
/
CompilationInfo.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# A small cmake script that writes the current git hash and time to a
# .cpp file
# Get the current time, remove the trailing newline and add quotes.
execute_process(COMMAND date OUTPUT_VARIABLE DATETIME_OF_COMPILATION)
string(REPLACE "\n" "" DATETIME_OF_COMPILATION "${DATETIME_OF_COMPILATION}")
set(DATETIME_OF_COMPILATION "\"${DATETIME_OF_COMPILATION}\"")
message(STATUS "DATETIME_OF_COMPILATION is ${DATETIME_OF_COMPILATION}" )
# Get the current git hash.
execute_process(COMMAND git log -1 --format="%H" OUTPUT_VARIABLE GIT_HASH)
if ((NOT DEFINED GIT_HASH) OR (GIT_HASH STREQUAL ""))
set(GIT_HASH "\"QLever compilation not taking place in a git repository\"")
endif()
message(STATUS "GIT_HASH is ${GIT_HASH}")
# Write the .cpp file.
set(CONSTANTS "#include \"CompilationInfo.h\"
namespace qlever::version {
constexpr std::string_view GitHash = ${GIT_HASH};
constexpr std::string_view GitShortHash = GitHash.substr(0, 6);
constexpr std::string_view DatetimeOfCompilation = ${DATETIME_OF_COMPILATION};
void copyVersionInfo() {
*gitShortHashWithoutLinking.wlock() = GitShortHash;
*datetimeOfCompilationWithoutLinking.wlock() = DatetimeOfCompilation;
}
}")
# For some reason `CMAKE_CURRENT_SOURCE_DIR` inside this script is
# `CMAKE_CURRENT_BINARY_DIR` in the main `CMakeLists.txt`.
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/CompilationInfo.cpp "${CONSTANTS}")