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 # Author: 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
18 CACHE DOC "Git version control tool")
20 if(NOT Git_EXECUTABLE)
21 set(_err_msg "Git executable not found")
23 message(FATAL_ERROR " ${_err_msg}")
24 elseif(NOT Git_FIND_QUIETLY)
25 message("${_err_msg}")
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")
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}")
43 message(FATAL_ERROR " ${_err_msg}")
44 elseif(NOT Git_FIND_QUIETLY)
45 message("${_err_msg}")
47 set(_git_version_ok FALSE)
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}")
53 message(FATAL_ERROR " ${_err_msg}")
54 elseif(NOT Git_FIND_QUIETLY)
55 message("${_err_msg}")
57 set(_git_version_ok FALSE)
62 include(FindPackageHandleStandardArgs)
63 find_package_handle_standard_args(Git DEFAULT_MSG
68 mark_as_advanced(Git_EXECUTABLE Git_VERSION)