Example: GNU Patch from CMake

To patch files in one’s own project, or when using other projects via FetchContent etc., it’s possible to patch source/header/etc. using GNU Patch and add_custom_command() with the benefit of CMake canonical approach (triggers only if source changes).

I have seen requests for this but didn’t find a cross-platform solution (Linux, MacOS, Windows) so I made an example. It requires that GNU Patch “patch” is available, which is usually is. On Windows, MSYS2 or WSL are used to get patch executable.