1 # Try to find the git version control tool
3 # The module defines the following variables:
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)
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")
22 message(FATAL_ERROR " ${_err_msg}")
23 elseif(NOT Git_FIND_QUIETLY)
24 message("${_err_msg}")
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")
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}")
41 message(FATAL_ERROR " ${_err_msg}")
42 elseif(NOT Git_FIND_QUIETLY)
43 message("${_err_msg}")
45 set(_git_version_ok FALSE)
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}")
50 message(FATAL_ERROR " ${_err_msg}")
51 elseif(NOT Git_FIND_QUIETLY)
52 message("${_err_msg}")
54 set(_git_version_ok FALSE)
59 include(FindPackageHandleStandardArgs)
60 find_package_handle_standard_args(Git DEFAULT_MSG
65 mark_as_advanced(Git_EXECUTABLE Git_VERSION)