-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.cmake
37 lines (36 loc) · 1.15 KB
/
git.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
find_package(Git)
if (!Git_FOUND)
set(GIT_EXECUTABLE git)
endif (!Git_FOUND)
# Master exists for rev-list
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}"
rev-parse --quiet --verify refs/heads/master
OUTPUT_VARIABLE GIT_MASTER_REF)
if ("${GIT_MASTER_REF}" STREQUAL "")
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}"
branch master origin/master)
else ()
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}"
update-ref refs/heads/master refs/remotes/origin/master
)
endif ()
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}" rev-list --count --first-parent refs/heads/master
OUTPUT_VARIABLE GIT_REVISION
)
string(STRIP "${GIT_REVISION}" GIT_REVISION)
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}" symbolic-ref --short HEAD
OUTPUT_VARIABLE GIT_BRANCH
)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
if ("${GIT_BRANCH}" STREQUAL "")
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_CURRENT_SOURCE_DIR}" rev-parse --short HEAD
OUTPUT_VARIABLE GIT_BRANCH
)
endif ()
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)