In this repo you'll find a single CMake module whose purpose is to apply patches to projects built with ExternalProject_Add()
.
generate_patch_commands(
<output var> [USE_GIT_AM] PATCHES /path/to/patches/*.patch [more patches])
The <output var>
will then contain a sequence of COMMAND ...
elements that apply the specified patches. Note that having the globbing expression that matches no files is permitted.
generate_patch_commands(
patch_commands USE_GIT_AM PATCHES
"${CMAKE_CURRENT_SOURCE_DIR}/patches/*.patch"
)
ExternalProject_Add(
...
PATCH_COMMAND git reset --hard ${git_tag}
${patch_commands}
...
)
As USE_GIT_AM
is used here, the patches will be applied by git am
, and are expected to be generated by git format-patch
If USE_GIT_AM
is not specified, patches will be applied by the patch
command. In such a case, this function is best used from a custom step created by ExternalProject_Add_Step()
that copies the source code from the source directory to the build directory and then applies the patches to the build directory.