FindPatch — CMake 4.4.2 Documentation

# 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 `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 was 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()