FindPatch — CMake 4.1.4 Documentation

# FindPatch

Added in version 3.10.

Finds the `patch` command-line executable for applying diff patches to original files.

## Imported Targets

This module provides the following Imported Targets:

`Patch::patch`

  Target encapsulating the `patch` command-line executable, available only if `patch` is found.

  Changed in version 4.0: This imported target is defined only when `CMAKE_ROLE` is `PROJECT`.

## Result Variables

This module defines the following variables:

`Patch_FOUND`

  Boolean indicating whether the `patch` command-line executable is found.

## Cache Variables

The following cache variables may also be set:

`Patch_EXECUTABLE`

  The path to the `patch` command-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()