-
-
Notifications
You must be signed in to change notification settings - Fork 637
/
Copy pathLIEFGit.cmake
80 lines (68 loc) · 2.13 KB
/
LIEFGit.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
if(__add_lief_git)
return()
endif()
set(__add_lief_git ON)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list --count ${LIEF_COMMIT_HASH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags HEAD --always
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} tag --list --points-at=HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_GIT_COMMIT_TAGGED
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(COMPARE NOTEQUAL "${LIEF_GIT_COMMIT_TAGGED}" "" LIEF_IS_TAGGED)
string(REGEX MATCHALL "([0-9]+)" VERSION_STRING "${LIEF_GIT_TAG}")
message(STATUS "Tagged: ${LIEF_IS_TAGGED}")
if (${LIEF_IS_TAGGED})
message(STATUS "Tag: ${LIEF_GIT_TAG}")
else()
if(LIEF_GIT_BRANCH MATCHES "^release[-/]")
string(REGEX MATCHALL "([0-9]+)" VERSION_STRING "${LIEF_GIT_BRANCH}")
message(STATUS "${VERSION_STRING}")
endif()
endif()
message(STATUS "Current branch: ${LIEF_GIT_BRANCH}")
if (VERSION_STRING)
list(LENGTH VERSION_STRING VERSION_STRING_LEN)
list(GET VERSION_STRING 0 LIEF_VERSION_MAJOR)
list(GET VERSION_STRING 1 LIEF_VERSION_MINOR)
if (VERSION_STRING_LEN GREATER 2)
list(GET VERSION_STRING 2 LIEF_VERSION_PATCH)
else()
set(LIEF_VERSION_PATCH 0)
endif()
if (NOT ${LIEF_IS_TAGGED})
if(LIEF_GIT_BRANCH MATCHES "^release[-/]")
message(STATUS "Release branch")
else()
MATH(EXPR LIEF_VERSION_MINOR "${LIEF_VERSION_MINOR}+1")
set(LIEF_VERSION_PATCH 0)
endif()
endif()
else()
set(LIEF_VERSION_MAJOR 0)
set(LIEF_VERSION_MINOR 0)
set(LIEF_VERSION_PATCH 0)
endif()