Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindGit.cmake
1 # The module defines the following variables:
2 #   GIT_EXECUTABLE - path to git command line client
3 #   GIT_FOUND - true if the command line client was found
4 #   GIT_VERSION_STRING - the version of git found (since CMake 2.8.8)
5 # Example usage:
6 #   find_package(Git)
7 #   if(GIT_FOUND)
8 #     message("git found: ${GIT_EXECUTABLE}")
9 #   endif()
10
11 #=============================================================================
12 # Copyright 2010 Kitware, Inc.
13 # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
14 #
15 # Distributed under the OSI-approved BSD License (the "License");
16 # see accompanying file Copyright.txt for details.
17 #
18 # This software is distributed WITHOUT ANY WARRANTY; without even the
19 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 # See the License for more information.
21 #=============================================================================
22 # (To distribute this file outside of CMake, substitute the full
23 #  License text for the above reference.)
24
25 # Look for 'git' or 'eg' (easy git)
26 #
27 set(git_names git eg)
28
29 # Prefer .cmd variants on Windows unless running in a Makefile
30 # in the MSYS shell.
31 #
32 if(WIN32)
33   if(NOT CMAKE_GENERATOR MATCHES "MSYS")
34     set(git_names git.cmd git eg.cmd eg)
35   endif()
36 endif()
37
38 find_program(GIT_EXECUTABLE
39   NAMES ${git_names}
40   PATH_SUFFIXES Git/cmd Git/bin
41   DOC "git command line client"
42   )
43 mark_as_advanced(GIT_EXECUTABLE)
44
45 if(GIT_EXECUTABLE)
46   execute_process(COMMAND ${GIT_EXECUTABLE} --version
47                   OUTPUT_VARIABLE git_version
48                   ERROR_QUIET
49                   OUTPUT_STRIP_TRAILING_WHITESPACE)
50   if (git_version MATCHES "^git version [0-9]")
51     string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
52   endif()
53   unset(git_version)
54 endif()
55
56 # Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
57 # all listed variables are TRUE
58
59 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
60 find_package_handle_standard_args(Git
61                                   REQUIRED_VARS GIT_EXECUTABLE
62                                   VERSION_VAR GIT_VERSION_STRING)