Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPM Patch step incorrectly assumes CMake external command is executed in shell, fails to apply multiple patches listed in PATCHES #651

Open
christopherbate opened this issue Mar 4, 2025 · 0 comments · May be fixed by #652

Comments

@christopherbate
Copy link

In CI environments, whenever my CPMAddPackage command
has PATCHES set with multiple files, I get an error

/usr/bin/patch: '&&': extra operand
/usr/bin/patch: Try '/usr/bin/patch --help' for more information.

This occurs because in function cpm_add_patches, the patch command is built by concatenating
a bunch of strings like

patch -p1 < "$first_patch_file" && patch -p1 < "$second_patch_file"

And then these strings are appended to the PATCH_COMMAND argument for hand-off to a downstream function (FetchContent?).

This assumes that the PATCH_COMMAND executor is a shell that understands things like &&, which apparently is not always the case.

After looking at CMake docs, I hacked together a basic workaround which appears to work. CMake apparently allows issuing multiple commands for the PATCH_COMMAND as long as you declare COMMAND for each subsequent command after the first:

PATCH_COMMAND
  patch -p1 -i $first_patch
  COMMAND patch -p1 -i $second_aptch
``` 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant