FindGit: support version number

This commit is contained in:
Rolf Eike Beer 2012-01-23 19:46:08 +01:00
parent 86c9604f98
commit a803a622d0
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
# The module defines the following variables:
# GIT_EXECUTABLE - path to git command line client
# GIT_FOUND - true if the command line client was found
# GIT_VERSION_STRING - the version of git found (since CMake 2.8.8)
# Example usage:
# find_package(Git)
# if(GIT_FOUND)
@ -9,6 +10,7 @@
#=============================================================================
# Copyright 2010 Kitware, Inc.
# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@ -40,8 +42,21 @@ find_program(GIT_EXECUTABLE
)
mark_as_advanced(GIT_EXECUTABLE)
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)
endif(GIT_EXECUTABLE)
# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
# all listed variables are TRUE
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE)
find_package_handle_standard_args(Git
REQUIRED_VARS GIT_EXECUTABLE
VERSION_VAR GIT_VERSION_STRING)