Made g_protonate (partially) work.
[gromacs/rigid-bodies.git] / cmake / FindGit.cmake
blob151190f858ae77daa761c5ca69f89b498194a673
1 # Try to find the git version control tool
2
3 # The module defines the following variables:
4
5 # Git_EXECUTABLE    - path the the git executable
6 # Git_VERSION       - git version
7 # Git_FOUND         - tru if git was found, false otherwise
9 # Author: Szilard Pall (pszilard@cbr.su.se)
11 if(Git_EXECUTABLE AND Git_VERSION)
12     set(Git_FIND_QUIETLY TRUE)
13 endif()
15 # search for git binary
16 find_program(Git_EXECUTABLE git
17     PATHS ENV PATH
18     CACHE DOC "Git version control tool")
20 if(NOT Git_EXECUTABLE)
21     set(_err_msg "Git executable not found")
22     if(Git_FIND_REQUIRED)
23         message(FATAL_ERROR " ${_err_msg}")
24     elseif(NOT Git_FIND_QUIETLY)
25         message("${_err_msg}")
26     endif()
27 endif()
29 # parse version
30 if(Git_EXECUTABLE AND NOT Git_VERSION)
31     execute_process(COMMAND ${Git_EXECUTABLE} "--version"
32         OUTPUT_VARIABLE _exec_out
33         OUTPUT_STRIP_TRAILING_WHITESPACE)
34     string(REGEX REPLACE "git version (.*)" "\\1" Git_VERSION ${_exec_out})
35     set(Git_VERSION ${Git_VERSION} CACHE STRING "Git version")
36     
37     # check version
38     set(_git_version_ok TRUE)
39     # this should at some point become VERSION_EQUAL
40     if(Git_FIND_VERSION_EXACT AND NOT Git_VERSION STREQUAL Git_FIND_VERSION)
41         set(_err_msg "Found git version ${Git_VERSION} but this does not match the requested ${Git_FIND_VERSION}")
42         if(Git_FIND_REQUIRED)
43             message(FATAL_ERROR " ${_err_msg}")
44         elseif(NOT Git_FIND_QUIETLY)
45             message("${_err_msg}")
46         endif()
47         set(_git_version_ok FALSE)
48     endif()
49     # this should at some point become VERSION_LESS
50     if(Git_FIND_VERSION AND Git_VERSION STRLESS Git_FIND_VERSION)
51         set(_err_msg "Found git version ${Git_VERSION} but this is less then the requested ${Git_FIND_VERSION}")
52         if(Git_FIND_REQUIRED)
53             message(FATAL_ERROR " ${_err_msg}")
54         elseif(NOT Git_FIND_QUIETLY)
55             message("${_err_msg}")
56         endif()
57         set(_git_version_ok FALSE)
58     endif()
60 endif()
61 set(Git_FOUND True)
62 include(FindPackageHandleStandardArgs)
63 find_package_handle_standard_args(Git DEFAULT_MSG 
64     Git_EXECUTABLE 
65     Git_VERSION
66     _git_version_ok)
68 mark_as_advanced(Git_EXECUTABLE Git_VERSION)