FindGit.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # Copyright 2010 Kitware, Inc.
  12. # Copyright 2012 Rolf Eike Beer <[email protected]>
  13. #
  14. # Distributed under the OSI-approved BSD License (the "License");
  15. # see accompanying file Copyright.txt for details.
  16. #
  17. # This software is distributed WITHOUT ANY WARRANTY; without even the
  18. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. # See the License for more information.
  20. #=============================================================================
  21. # (To distribute this file outside of CMake, substitute the full
  22. # License text for the above reference.)
  23. # Look for 'git' or 'eg' (easy git)
  24. #
  25. set(git_names git eg)
  26. # Prefer .cmd variants on Windows unless running in a Makefile
  27. # in the MSYS shell.
  28. #
  29. if(WIN32)
  30. if(NOT CMAKE_GENERATOR MATCHES "MSYS")
  31. set(git_names git.cmd git eg.cmd eg)
  32. endif()
  33. endif()
  34. find_program(GIT_EXECUTABLE
  35. NAMES ${git_names}
  36. PATH_SUFFIXES Git/cmd Git/bin
  37. DOC "git command line client"
  38. )
  39. mark_as_advanced(GIT_EXECUTABLE)
  40. if(GIT_EXECUTABLE)
  41. execute_process(COMMAND ${GIT_EXECUTABLE} --version
  42. OUTPUT_VARIABLE git_version
  43. ERROR_QUIET
  44. OUTPUT_STRIP_TRAILING_WHITESPACE)
  45. if (git_version MATCHES "^git version [0-9]")
  46. string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
  47. endif()
  48. unset(git_version)
  49. endif()
  50. # Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
  51. # all listed variables are TRUE
  52. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  53. find_package_handle_standard_args(Git
  54. REQUIRED_VARS GIT_EXECUTABLE
  55. VERSION_VAR GIT_VERSION_STRING)