-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtfc_version.cmake
80 lines (76 loc) · 2.22 KB
/
tfc_version.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Run this with CMake in "script mode" (-P flag) at build time
# find Git and if available set GIT_HASH variable
find_package(Git REQUIRED)
if(GIT_FOUND)
execute_process(
COMMAND git config --global --add safe.directory ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git remote get-url origin
OUTPUT_VARIABLE GIT_REPO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --pretty=format:%H
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --pretty=format:"%an <%ae>"
OUTPUT_VARIABLE GIT_AUTHOR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git branch --show-current
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git describe --tags --abbrev=1
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git diff --shortstat
OUTPUT_VARIABLE GIT_IS_DIRTY_INTERMEDIATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --pretty=format:%as
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND date +"%Y-%m-%d %H:%M:%S"
OUTPUT_VARIABLE BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(FATAL_ERROR "Git not found, cannot generate version.hpp")
endif()
# Write git dirty if GIT_DIRTY_INTERMEDIATE is not empty
if(NOT "${GIT_IS_DIRTY_INTERMEDIATE}" STREQUAL "")
set(GIT_IS_DIRTY "dirty")
else()
set(GIT_IS_DIRTY "")
endif()
# Print all git fields
message(STATUS "GIT_REPO: ${GIT_REPO}")
message(STATUS "GIT_HASH: ${GIT_HASH}")
message(STATUS "GIT_AUTHOR: ${GIT_AUTHOR}")
message(STATUS "GIT_BRANCH: ${GIT_BRANCH}")
message(STATUS "GIT_TAG: ${GIT_TAG}")
message(STATUS "GIT_IS_DIRTY: ${GIT_IS_DIRTY}")
message(STATUS "GIT_COMMIT_DATE: ${GIT_COMMIT_DATE}")
message(STATUS "BUILD_DATE: ${BUILD_DATE}")
function(priv_get_directory DIRECTORY)
set(${DIRECTORY} ${CMAKE_CURRENT_FUNCTION_LIST_DIR} PARENT_SCOPE)
endfunction()
priv_get_directory(THIS_DIRECTORY)
# generate file version.hpp based on version.hpp.in
configure_file(
${THIS_DIRECTORY}/inc/version.hpp.in
${OUT_FILE}
@ONLY
)