-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.cmake
60 lines (53 loc) · 2.04 KB
/
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
if(GIT_EXECUTABLE)
get_filename_component(SRC_DIR ${SRC} DIRECTORY)
# Figure out which branch we are on
execute_process(
COMMAND ${GIT_EXECUTABLE} branch --show-current
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_BRANCH
RESULT_VARIABLE GIT_BRANCH_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_BRANCH_ERROR_CODE)
# Generate a git-describe version string.
# Have to do this in two parts; thanks, git!
if (GIT_BRANCH)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --all --always --exclude "${GIT_BRANCH}" --exclude "*/${GIT_BRANCH}" HEAD
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION_A
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --all --always HEAD
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION_A
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --dirty --always
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION_B
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# A ~ "heads/master-506-ge042461" B ~ "e042461-dirty"
if(GIT_DESCRIBE_VERSION_A AND GIT_DESCRIBE_VERSION_B)
string(REGEX REPLACE "^[^/]*/" "" GIT_DESCRIBE_VERSION ${GIT_DESCRIBE_VERSION_A})
string(REGEX REPLACE "-g[0-9a-fA-F]+" "" GIT_DESCRIBE_VERSION ${GIT_DESCRIBE_VERSION})
string(APPEND GIT_DESCRIBE_VERSION "-" ${GIT_DESCRIBE_VERSION_B})
set(SMHASHER3_GIT_VERSION ${GIT_DESCRIBE_VERSION})
endif()
if((NOT GIT_DESCRIBE_VERSION_A) AND GIT_DESCRIBE_VERSION_B)
string(CONCAT SMHASHER3_GIT_VERSION "master-unknown-" ${GIT_DESCRIBE_VERSION_B})
endif()
endif()
endif()
if(NOT DEFINED SMHASHER3_GIT_VERSION)
set(SMHASHER3_GIT_VERSION "master-unknown")
endif()
configure_file(${SRC} ${DST} @ONLY)