1#.rst: 2# FindGit 3# ------- 4# 5# 6# 7# The module defines the following variables: 8# 9# :: 10# 11# GIT_EXECUTABLE - path to git command line client 12# GIT_FOUND - true if the command line client was found 13# GIT_VERSION_STRING - the version of git found (since CMake 2.8.8) 14# 15# Example usage: 16# 17# :: 18# 19# find_package(Git) 20# if(GIT_FOUND) 21# message("git found: ${GIT_EXECUTABLE}") 22# endif() 23 24#============================================================================= 25# Copyright 2010 Kitware, Inc. 26# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> 27# 28# Distributed under the OSI-approved BSD License (the "License"); 29# see below. 30# 31# This software is distributed WITHOUT ANY WARRANTY; without even the 32# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 33# See the License for more information. 34#============================================================================= 35# 36# Redistribution and use in source and binary forms, with or without 37# modification, are permitted provided that the following conditions 38# are met: 39# 40# * Redistributions of source code must retain the above copyright 41# notice, this list of conditions and the following disclaimer. 42# 43# * Redistributions in binary form must reproduce the above copyright 44# notice, this list of conditions and the following disclaimer in the 45# documentation and/or other materials provided with the distribution. 46# 47# * Neither the names of Kitware, Inc., the Insight Software Consortium, 48# nor the names of their contributors may be used to endorse or promote 49# products derived from this software without specific prior written 50# permission. 51# 52# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 53# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 54# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 55# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 56# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 57# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 58# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 59# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 60# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 61# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 62# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63#============================================================================= 64 65# Look for 'git' or 'eg' (easy git) 66# 67set(git_names git eg) 68 69# Prefer .cmd variants on Windows unless running in a Makefile 70# in the MSYS shell. 71# 72if(WIN32) 73 if(NOT CMAKE_GENERATOR MATCHES "MSYS") 74 set(git_names git.cmd git eg.cmd eg) 75 # GitHub search path for Windows 76 set(github_path "$ENV{LOCALAPPDATA}/Github/PortableGit*/bin") 77 file(GLOB github_path "${github_path}") 78 endif() 79endif() 80 81find_program(GIT_EXECUTABLE 82 NAMES ${git_names} 83 PATHS ${github_path} 84 PATH_SUFFIXES Git/cmd Git/bin 85 DOC "git command line client" 86 ) 87mark_as_advanced(GIT_EXECUTABLE) 88 89if(GIT_EXECUTABLE) 90 execute_process(COMMAND ${GIT_EXECUTABLE} --version 91 OUTPUT_VARIABLE git_version 92 ERROR_QUIET 93 OUTPUT_STRIP_TRAILING_WHITESPACE) 94 if (git_version MATCHES "^git version [0-9]") 95 string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}") 96 endif() 97 unset(git_version) 98endif() 99 100# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if 101# all listed variables are TRUE 102 103include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 104find_package_handle_standard_args(Git 105 REQUIRED_VARS GIT_EXECUTABLE 106 VERSION_VAR GIT_VERSION_STRING) 107