Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
FindGit.cmake
Go to the documentation of this file.
1 #
2 # FindGit
3 #
4 
5 set(git_candidates git eg)
6 
7 if(WIN32)
8  list(APPEND git_candidates eg.cmd)
9  if(NOT MSYS)
10  # We don't append git.cmd, since it does not correctly return
11  # exit codes, see http://code.google.com/p/msysgit/issues/detail?id=428
12  list(APPEND git_candidates git.cmd)
13  endif()
14 endif()
15 
16 find_program(GIT_EXECUTABLE ${git_candidates}
17  PATHS
18  "C:/Program Files/Git/bin"
19  "C:/Program Files (x86)/Git/bin"
20  DOC "git command line client")
21 mark_as_advanced(GIT_EXECUTABLE)
22 
23 if(GIT_EXECUTABLE)
24 
25  macro(GIT_IS_REPO dir result_var)
26  # check if ${dir} is a proper Git repository
27  execute_process(COMMAND ${GIT_EXECUTABLE} rev-list -n 1 HEAD
28  WORKING_DIRECTORY ${dir}
29  RESULT_VARIABLE GIT_error
30  OUTPUT_QUIET
31  ERROR_QUIET)
32  if(GIT_error EQUAL 0)
33  set(${result_var} 1)
34  else()
35  set(${result_var} 0)
36  endif()
37  endmacro()
38 
39  macro(GIT_WC_INFO dir prefix)
40  execute_process(COMMAND ${GIT_EXECUTABLE} rev-list -n 1 HEAD
41  WORKING_DIRECTORY ${dir}
42  ERROR_VARIABLE GIT_error
43  OUTPUT_VARIABLE ${prefix}_WC_REVISION_HASH
44  OUTPUT_STRIP_TRAILING_WHITESPACE)
45  if(NOT ${GIT_error} EQUAL 0)
46  message(SEND_ERROR "Command \"${GIT_EXECUTBALE} rev-list -n 1 HEAD\" in directory ${dir} failed with output:\n${GIT_error}")
47  else()
48  execute_process(COMMAND ${GIT_EXECUTABLE} name-rev ${${prefix}_WC_REVISION_HASH}
49  WORKING_DIRECTORY ${dir}
50  OUTPUT_VARIABLE ${prefix}_WC_REVISION_NAME
51  OUTPUT_STRIP_TRAILING_WHITESPACE)
52  endif()
53 
54  set(${prefix}_WC_GITSVN 0)
55  # In case, git-svn is used, attempt to extract svn info
56  execute_process(COMMAND ${GIT_EXECUTABLE} svn info
57  WORKING_DIRECTORY ${dir}
58  ERROR_VARIABLE git_svn_info_error
59  OUTPUT_VARIABLE ${prefix}_WC_INFO
60  RESULT_VARIABLE git_svn_info_result
61  OUTPUT_STRIP_TRAILING_WHITESPACE)
62 
63  if(${git_svn_info_result} EQUAL 0)
64  set(${prefix}_WC_GITSVN 1)
65  string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
66  "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
67  string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
68  "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
69  string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
70  "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
71  string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
72  "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
73  string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
74  "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
75  endif()
76 
77  endmacro()
78 endif()
79 
80 include(FindPackageHandleStandardArgs)
81 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Git DEFAULT_MSG GIT_EXECUTABLE)
GIT_WC_INFO(dir, prefix)
GIT_IS_REPO(dir, result_var)
static void info(const char *fmt,...)
Definition: svm.cpp:100