minor updates to FindGit and FindOpenMM
[gromacs/rigid-bodies.git] / cmake / FindGit.cmake
blob6f3631117d36a7327e289ae0ca4491aecba35272
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     if(Git_FIND_VERSION_EXACT AND NOT Git_VERSION VERSION_EQUAL Git_FIND_VERSION)
40         set(_err_msg "Found git version ${Git_VERSION} but this does not match the requested ${Git_FIND_VERSION}")
41         if(Git_FIND_REQUIRED)
42             message(FATAL_ERROR " ${_err_msg}")
43         elseif(NOT Git_FIND_QUIETLY)
44             message("${_err_msg}")
45         endif()
46         set(_git_version_ok FALSE)
47     endif()
48     if(Git_FIND_VERSION AND Git_VERSION VERSION_LESS Git_FIND_VERSION)
49         set(_err_msg "Found git version ${Git_VERSION} but this is less then the requested ${Git_FIND_VERSION}")
50         if(Git_FIND_REQUIRED)
51             message(FATAL_ERROR " ${_err_msg}")
52         elseif(NOT Git_FIND_QUIETLY)
53             message("${_err_msg}")
54         endif()
55         set(_git_version_ok FALSE)
56     endif()
58 endif()
59 set(Git_FOUND True)
60 include(FindPackageHandleStandardArgs)
61 find_package_handle_standard_args(Git DEFAULT_MSG 
62     Git_EXECUTABLE 
63     Git_VERSION
64     _git_version_ok)
66 mark_as_advanced(Git_EXECUTABLE Git_VERSION)