| 1 |
# In case Git is not available, default is empty string |
| •2 |
set(D3_GIT_HASH "") |
| 3 |
|
| 4 |
find_package(Git QUIET) |
| 5 |
if(GIT_FOUND) |
| 6 |
execute_process( |
| 7 |
COMMAND ${GIT_EXECUTABLE} describe --always --dirty |
| 8 |
OUTPUT_VARIABLE D3_GIT_HASH |
| 9 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 10 |
ERROR_QUIET |
| 11 |
) |
| •12 |
endif() |
| 13 |
if(NOT D3_GIT_HASH STREQUAL "") |
| 14 |
file(WRITE ${SOURCE_DIR}/git-hash.txt ${D3_GIT_HASH}) |
| 15 |
else() |
| 16 |
# Try to read pregenerated file with commit hash on it (archive version of repository) |
| 17 |
if(EXISTS ${SOURCE_DIR}/git-hash.txt) |
| 18 |
file(READ ${SOURCE_DIR}/git-hash.txt D3_GIT_HASH) |
| 19 |
endif() |
| 20 |
endif() |
| 21 |
|
| 22 |
message(STATUS "Git hash is ${D3_GIT_HASH}") |
| 23 |
|
| 24 |
configure_file( |
| 25 |
${SOURCE_DIR}/lib/d3_version.h.in |
| 26 |
${TARGET_DIR}/lib/d3_version.h |
| 27 |
@ONLY |
| 28 |
) |