FindPatch.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPatch
  5. ---------
  6. The module defines the following variables:
  7. ``Patch_EXECUTABLE``
  8. Path to patch command-line executable.
  9. ``Patch_FOUND``
  10. True if the patch command-line executable was found.
  11. The following :prop_tgt:`IMPORTED` targets are also defined:
  12. ``Patch::patch``
  13. The command-line executable.
  14. Example usage:
  15. .. code-block:: cmake
  16. find_package(Patch)
  17. if(Patch_FOUND)
  18. message("Patch found: ${Patch_EXECUTABLE}")
  19. endif()
  20. #]=======================================================================]
  21. set(_doc "Patch command line executable")
  22. set(_patch_path )
  23. if(CMAKE_HOST_WIN32)
  24. set(_patch_path
  25. "$ENV{LOCALAPPDATA}/Programs/Git/bin"
  26. "$ENV{LOCALAPPDATA}/Programs/Git/usr/bin"
  27. "$ENV{APPDATA}/Programs/Git/bin"
  28. "$ENV{APPDATA}/Programs/Git/usr/bin"
  29. )
  30. endif()
  31. # First search the PATH
  32. find_program(Patch_EXECUTABLE
  33. NAME patch
  34. PATHS ${_patch_path}
  35. DOC ${_doc}
  36. )
  37. if(CMAKE_HOST_WIN32)
  38. # Now look for installations in Git/ directories under typical installation
  39. # prefixes on Windows.
  40. find_program(Patch_EXECUTABLE
  41. NAMES patch
  42. PATH_SUFFIXES Git/usr/bin Git/bin GnuWin32/bin
  43. DOC ${_doc}
  44. )
  45. endif()
  46. if(Patch_EXECUTABLE AND NOT TARGET Patch::patch)
  47. add_executable(Patch::patch IMPORTED)
  48. set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${Patch_EXECUTABLE})
  49. endif()
  50. unset(_patch_path)
  51. unset(_doc)
  52. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  53. find_package_handle_standard_args(Patch
  54. REQUIRED_VARS Patch_EXECUTABLE)