From a803a622d052e6b50873f6bf6a3ab224f656333f Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Mon, 23 Jan 2012 19:46:08 +0100 Subject: FindGit: support version number --- Modules/FindGit.cmake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake index 503b640..f89d1af 100644 --- a/Modules/FindGit.cmake +++ b/Modules/FindGit.cmake @@ -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 # # 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) -- cgit v0.12