FindPatch

在 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.

在 4.0 版的變更: This imported target is defined only when CMAKE_ROLE is PROJECT.

結果變數

This module defines the following variables:

Patch_FOUND

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

快取變數

The following cache variables may also be set:

Patch_EXECUTABLE

The path to the patch command-line executable.

範例

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()