Merge branch 'master' of git@git.gromacs.org:gromacs
[gromacs/rigid-bodies.git] / cmake / FindGit.cmake
blob3d553ecc24e0a9221b510a6761db171384693f80
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 # 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     DOC "Git version control tool")
19 if(NOT Git_EXECUTABLE)
20     set(_err_msg "Git executable not found")
21     if(Git_FIND_REQUIRED)
22         message(FATAL_ERROR " ${_err_msg}")
23     elseif(NOT Git_FIND_QUIETLY)
24         message("${_err_msg}")
25     endif()
26 endif()
28 # parse version
29 if(Git_EXECUTABLE AND NOT Git_VERSION)
30     execute_process(COMMAND ${Git_EXECUTABLE} "--version"
31         OUTPUT_VARIABLE _exec_out
32         OUTPUT_STRIP_TRAILING_WHITESPACE)
33     string(REGEX REPLACE "git version (.*)" "\\1" Git_VERSION ${_exec_out})
34     set(Git_VERSION ${Git_VERSION} CACHE STRING "Git version")
35     
36     # check version
37     set(_git_version_ok TRUE)
38     if(Git_FIND_VERSION_EXACT AND NOT Git_VERSION VERSION_EQUAL Git_FIND_VERSION)
39         set(_err_msg "Found git version ${Git_VERSION} but this does not match the requested ${Git_FIND_VERSION}")
40         if(Git_FIND_REQUIRED)
41             message(FATAL_ERROR " ${_err_msg}")
42         elseif(NOT Git_FIND_QUIETLY)
43             message("${_err_msg}")
44         endif()
45         set(_git_version_ok FALSE)
46     endif()
47     if(Git_FIND_VERSION AND Git_VERSION VERSION_LESS Git_FIND_VERSION)
48         set(_err_msg "Found git version ${Git_VERSION} but this is less then the requested ${Git_FIND_VERSION}")
49         if(Git_FIND_REQUIRED)
50             message(FATAL_ERROR " ${_err_msg}")
51         elseif(NOT Git_FIND_QUIETLY)
52             message("${_err_msg}")
53         endif()
54         set(_git_version_ok FALSE)
55     endif()
57 endif()
58 set(Git_FOUND True)
59 include(FindPackageHandleStandardArgs)
60 find_package_handle_standard_args(Git DEFAULT_MSG 
61     Git_EXECUTABLE 
62     Git_VERSION
63     _git_version_ok)
65 mark_as_advanced(Git_EXECUTABLE Git_VERSION)