FindPatch
Added in version 3.10.
Finds the patch command-line executable for applying diff patches to original files:
find_package(Patch [...])
Imported Targets
This module provides the following Imported Targets:
-
Patch::patch -
Target encapsulating the
patchcommand-line executable, available only ifpatchis found.Changed in version 4.0: This imported target is defined only when
CMAKE_ROLEisPROJECT.
Result Variables
This module defines the following variables:
-
Patch_FOUND -
Boolean indicating whether the
patchcommand-line executable was found.
Cache Variables
The following cache variables may also be set:
-
Patch_EXECUTABLE -
The path to the
patchcommand-line executable.
Examples
Finding patch command and executing it in a process:
find_package(Patch)
if(Patch_FOUND)
execute_process(
COMMAND ${Patch_EXECUTABLE} -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/src.patch
)
endif()
The imported target can be used, for example, inside the add_custom_command() command, which patches the given file when some build rule depends on its output:
find_package(Patch)
if(TARGET Patch::patch)
# Executed when some build rule depends on the src.c file.
add_custom_command(
OUTPUT src.c
COMMAND Patch::patch -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/src.patch
# ...
)
endif()
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/module/FindPatch.html