forked from ata4/angrylion-rdp-plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-version.cmake
55 lines (50 loc) · 1.54 KB
/
git-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
set(GIT_BRANCH "unknown")
set(GIT_COMMIT_DATE "unknown")
set(GIT_COMMIT_HASH "unknown")
set(GIT_TAG "unknown")
find_package(Git)
if(GIT_FOUND AND EXISTS "${SOURCE_DIR}/.git/")
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_BRANCH_RESULT
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${GIT_BRANCH_RESULT} EQUAL 0)
message(WARNING "git rev-parse failed, unknown branch.")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --format=%cs
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_COMMIT_DATE_RESULT
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${GIT_COMMIT_DATE_RESULT} EQUAL 0)
message(WARNING "git show failed, unknown commit date.")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --format=%h
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_COMMIT_HASH_RESULT
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${GIT_COMMIT_HASH_RESULT} EQUAL 0)
message(WARNING "git show failed, unknown commit hash.")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_TAG_RESULT
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${GIT_TAG_RESULT} EQUAL 0)
message(WARNING "git describe failed, unknown tag.")
endif()
else()
message(WARNING "git not found or not a git repo.")
endif()
configure_file(${PATH_VERSION}.in ${PATH_VERSION} @ONLY)