CPM.cmake
CPM.cmake copied to clipboard
Enhancement: add option PATCHES in which we can pass filepathes for patches to apply to the lib/package
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?
- Create patch:
somehow get the lib
cd the_lib_folder
git init
git add .
git commit -m "initial"
- edit something, use your preferred method to change the code
- get your edits as a patch file(s) :
git diff | tee /path_to_your_package/patches/pkg_name/patch_name.patch
- apply patches.
apply -p1 -rnN -d ${library_name_SOURCE_DIR} -i filepath_to_the_patch
there's also agit am
command, you can find it somewhere at internet just googling, it will do the same, maybe its better option because IDK is theapply
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 )