-
Notifications
You must be signed in to change notification settings - Fork 6
/
compiletime.cmake
53 lines (49 loc) · 1.24 KB
/
compiletime.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if (${NO_GIT})
set(GIT "GIT-NOTFOUND")
else()
find_program(GIT git)
endif()
if (${GIT} STREQUAL "GIT-NOTFOUND")
set(git_output "UNKNOWN")
set(git_changed 0)
set(git_version "v${FALLBACK_VERSION}?")
else()
execute_process(
COMMAND ${GIT} rev-parse --verify HEAD
OUTPUT_VARIABLE git_output OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT} describe HEAD
OUTPUT_VARIABLE git_descr OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT} diff --exit-code
OUTPUT_QUIET
ERROR_QUIET
RESULT_VARIABLE git_changed
)
set(git_version "*.*.*")
execute_process(
COMMAND ${GIT} describe --tags --match=v[0-9]* --abbrev=0
OUTPUT_VARIABLE git_version OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT} branch
OUTPUT_VARIABLE git_test OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (git_version STREQUAL git_descr)
else()
set(git_version ${git_version}+)
endif()
endif()
string(TIMESTAMP date "%Y-%m-%d %H:%M:%S")
file(WRITE ${OUTPUT_FILE}
"/**
* Generated at compile time on ${date}
*/
#define DFT2LNTROOT \"${DFTROOT}\"
#define COMPILETIME_DATE \"${date}\"
#define COMPILETIME_GITREV \"${git_output}\"
#define COMPILETIME_GITCHANGED ${git_changed}
#define COMPILETIME_GITVERSION \"${git_version}\"
")