CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Enhancement: add option PATCHES in which we can pass filepathes for patches to apply to the lib/package

Open Gerodote opened this issue 11 months ago • 16 comments

Assume we have a bad library that needs to be patched and we don't want to create a pull request, wait until a miracle happens and so on, or library just don't have github/gitlab pull request capability.

We would like to make a patch.

How to?

  1. Create patch: somehow get the lib cd the_lib_folder git init git add . git commit -m "initial"
  2. edit something, use your preferred method to change the code
  3. get your edits as a patch file(s) : git diff | tee /path_to_your_package/patches/pkg_name/patch_name.patch
  4. apply patches. apply -p1 -rnN -d ${library_name_SOURCE_DIR} -i filepath_to_the_patch there's also a git am command, you can find it somewhere at internet just googling, it will do the same, maybe its better option because IDK is the apply command portable on Windows and other environments.

How to apply patches in cmake ? Current solution:

CPMAddPackage(pkg_name ...)
execute_process(COMMAND apply -rnN -p1 -d ${library_name_SOURCE_DIR} -i ${CMAKE_CURRENT_SOURCE_DIR}/patches/pkg_name/patch_name.patch  ... ) # -N is essential. it won't allow patch twice.

What is the proposal?

Add PATCHES option in CPMAddPackage . ( Maybe in CPMFindPackage too ). It should take filepathes for patches. e.g. it should take ${CMAKE_CURRENT_SOURCE_DIR}/patches/${pkg_name}/* ( it can be a list of patches, which we could get using file(GLOB_RECURSE pkg_name_patches CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/patches/pkg_name/*.patch )

Gerodote avatar Aug 07 '23 12:08 Gerodote