FindPatch.cmake 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #
  7. # The module defines the following variables:
  8. #
  9. # ``Patch_EXECUTABLE``
  10. # Path to patch command-line executable.
  11. # ``Patch_FOUND``
  12. # True if the patch command-line executable was found.
  13. #
  14. # The following :prop_tgt:`IMPORTED` targets are also defined:
  15. #
  16. # ``Patch::patch``
  17. # The command-line executable.
  18. #
  19. # Example usage:
  20. #
  21. # .. code-block:: cmake
  22. #
  23. # find_package(Patch)
  24. # if(Patch_FOUND)
  25. # message("Patch found: ${Patch_EXECUTABLE}")
  26. # endif()
  27. set(_doc "Patch command line executable")
  28. set(_patch_path )
  29. if(CMAKE_HOST_WIN32)
  30. set(_patch_path
  31. "$ENV{LOCALAPPDATA}/Programs/Git/bin"
  32. "$ENV{LOCALAPPDATA}/Programs/Git/usr/bin"
  33. "$ENV{APPDATA}/Programs/Git/bin"
  34. "$ENV{APPDATA}/Programs/Git/usr/bin"
  35. )
  36. endif()
  37. # First search the PATH
  38. find_program(Patch_EXECUTABLE
  39. NAME patch
  40. PATHS ${_patch_path}
  41. DOC ${_doc}
  42. )
  43. if(CMAKE_HOST_WIN32)
  44. # Now look for installations in Git/ directories under typical installation
  45. # prefixes on Windows.
  46. find_program(Patch_EXECUTABLE
  47. NAMES patch
  48. PATH_SUFFIXES Git/usr/bin Git/bin GnuWin32/bin
  49. DOC ${_doc}
  50. )
  51. endif()
  52. if(Patch_EXECUTABLE AND NOT TARGET Patch::patch)
  53. add_executable(Patch::patch IMPORTED)
  54. set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${Patch_EXECUTABLE})
  55. endif()
  56. unset(_patch_path)
  57. unset(_doc)
  58. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  59. find_package_handle_standard_args(Patch
  60. REQUIRED_VARS Patch_EXECUTABLE)