cmake/Modules/FindGit.cmake

86 lines
2.4 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2014-08-03 19:52:23 +02:00
#.rst:
# FindGit
# -------
#
2010-06-23 01:18:35 +03:00
# The module defines the following variables:
2014-08-03 19:52:23 +02:00
#
2016-03-13 13:35:51 +01:00
# ``GIT_EXECUTABLE``
# Path to Git command-line client.
# ``Git_FOUND``, ``GIT_FOUND``
# True if the Git command-line client was found.
# ``GIT_VERSION_STRING``
# The version of Git found.
2014-08-03 19:52:23 +02:00
#
2010-06-23 01:18:35 +03:00
# Example usage:
2014-08-03 19:52:23 +02:00
#
2016-03-13 13:35:51 +01:00
# .. code-block:: cmake
2014-08-03 19:52:23 +02:00
#
# find_package(Git)
2016-03-13 13:35:51 +01:00
# if(Git_FOUND)
# message("Git found: ${GIT_EXECUTABLE}")
2014-08-03 19:52:23 +02:00
# endif()
2010-06-23 01:18:35 +03:00
# Look for 'git' or 'eg' (easy git)
#
set(git_names git eg)
# Prefer .cmd variants on Windows unless running in a Makefile
# in the MSYS shell.
#
2017-04-14 19:02:05 +02:00
if(CMAKE_HOST_WIN32)
2010-06-23 01:18:35 +03:00
if(NOT CMAKE_GENERATOR MATCHES "MSYS")
set(git_names git.cmd git eg.cmd eg)
2015-04-27 22:25:09 +02:00
# GitHub search path for Windows
2016-07-09 11:21:54 +02:00
file(GLOB github_path
"$ENV{LOCALAPPDATA}/Github/PortableGit*/cmd"
"$ENV{LOCALAPPDATA}/Github/PortableGit*/bin"
)
2016-03-13 13:35:51 +01:00
# SourceTree search path for Windows
set(_git_sourcetree_path "$ENV{LOCALAPPDATA}/Atlassian/SourceTree/git_local/bin")
2010-06-23 01:18:35 +03:00
endif()
endif()
2017-04-14 19:02:05 +02:00
# First search the PATH and specific locations.
2010-06-23 01:18:35 +03:00
find_program(GIT_EXECUTABLE
NAMES ${git_names}
2016-03-13 13:35:51 +01:00
PATHS ${github_path} ${_git_sourcetree_path}
DOC "Git command line client"
2010-06-23 01:18:35 +03:00
)
2017-04-14 19:02:05 +02:00
if(CMAKE_HOST_WIN32)
# Now look for installations in Git/ directories under typical installation
# prefixes on Windows. Exclude PATH from this search because VS 2017's
# command prompt happens to have a PATH entry with a Git/ subdirectory
# containing a minimal git not meant for general use.
find_program(GIT_EXECUTABLE
NAMES ${git_names}
PATH_SUFFIXES Git/cmd Git/bin
NO_SYSTEM_ENVIRONMENT_PATH
DOC "Git command line client"
)
endif()
2010-06-23 01:18:35 +03:00
mark_as_advanced(GIT_EXECUTABLE)
2016-03-13 13:35:51 +01:00
unset(git_names)
unset(_git_sourcetree_path)
2012-04-19 19:04:21 +03:00
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} --version
OUTPUT_VARIABLE git_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (git_version MATCHES "^git version [0-9]")
string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
endif()
unset(git_version)
2013-03-16 19:13:01 +02:00
endif()
2012-04-19 19:04:21 +03:00
2011-02-07 16:37:25 +01:00
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
2012-04-19 19:04:21 +03:00
find_package_handle_standard_args(Git
REQUIRED_VARS GIT_EXECUTABLE
VERSION_VAR GIT_VERSION_STRING)