Merge topic 'cxx-checks-tolerate-unused-arguments'
[kiteware-cmake.git] / Modules / FindPatch.cmake
blobf4fe4a6149ba9ae5a6cae3f1d5c7cb6e40dc8975
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindPatch
6 ---------
8 .. versionadded:: 3.10
10 The module defines the following variables:
12 ``Patch_EXECUTABLE``
13   Path to patch command-line executable.
14 ``Patch_FOUND``
15   True if the patch command-line executable was found.
17 The following :prop_tgt:`IMPORTED` targets are also defined:
19 ``Patch::patch``
20   The command-line executable.
22 Example usage:
24 .. code-block:: cmake
26    find_package(Patch)
27    if(Patch_FOUND)
28      message("Patch found: ${Patch_EXECUTABLE}")
29    endif()
30 #]=======================================================================]
32 set(_doc "Patch command line executable")
33 set(_patch_path )
35 if(CMAKE_HOST_WIN32)
36   set(_patch_path
37     "$ENV{LOCALAPPDATA}/Programs/Git/bin"
38     "$ENV{LOCALAPPDATA}/Programs/Git/usr/bin"
39     "$ENV{APPDATA}/Programs/Git/bin"
40     "$ENV{APPDATA}/Programs/Git/usr/bin"
41     )
42 endif()
44 # First search the PATH
45 find_program(Patch_EXECUTABLE
46   NAMES patch
47   PATHS ${_patch_path}
48   DOC ${_doc}
49   )
51 if(CMAKE_HOST_WIN32)
52   # Now look for installations in Git/ directories under typical installation
53   # prefixes on Windows.
54   find_program(Patch_EXECUTABLE
55     NAMES patch
56     PATH_SUFFIXES Git/usr/bin Git/bin GnuWin32/bin
57     DOC ${_doc}
58     )
59 endif()
61 if(Patch_EXECUTABLE AND NOT TARGET Patch::patch)
62   add_executable(Patch::patch IMPORTED)
63   set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${Patch_EXECUTABLE})
64 endif()
66 unset(_patch_path)
67 unset(_doc)
69 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
70 find_package_handle_standard_args(Patch
71                                   REQUIRED_VARS Patch_EXECUTABLE)