-
Notifications
You must be signed in to change notification settings - Fork 54
/
FindGit.cmake
34 lines (31 loc) · 1.15 KB
/
FindGit.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
SET(Git_FOUND FALSE)
FIND_PROGRAM(Git_EXECUTABLE git
DOC "git command line client")
MARK_AS_ADVANCED(Git_EXECUTABLE)
IF(Git_EXECUTABLE)
SET(Git_FOUND TRUE)
MACRO(Git_WC_INFO dir prefix)
EXECUTE_PROCESS(COMMAND ${Git_EXECUTABLE} rev-list -n 1 HEAD
WORKING_DIRECTORY ${dir}
ERROR_VARIABLE Git_error
OUTPUT_VARIABLE ${prefix}_WC_REVISION_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${Git_error} EQUAL 0)
MESSAGE(SEND_ERROR "Command \"${Git_EXECUTBALE} rev-list -n 1 HEAD\" in directory ${dir} failed with output:\n${Git_error}")
ELSE(NOT ${Git_error} EQUAL 0)
EXECUTE_PROCESS(COMMAND ${Git_EXECUTABLE} name-rev ${${prefix}_WC_REVISION_HASH}
WORKING_DIRECTORY ${dir}
OUTPUT_VARIABLE ${prefix}_WC_REVISION_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF(NOT ${Git_error} EQUAL 0)
ENDMACRO(Git_WC_INFO)
ENDIF(Git_EXECUTABLE)
IF(NOT Git_FOUND)
IF(NOT Git_FIND_QUIETLY)
MESSAGE(STATUS "Git was not found")
ELSE(NOT Git_FIND_QUIETLY)
if(Git_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Git was not found")
ENDIF(Git_FIND_REQUIRED)
ENDIF(NOT Git_FIND_QUIETLY)
ENDIF(NOT Git_FOUND)