Skip to content

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

Open
@christopherbate

Description

@christopherbate

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
``` 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @christopherbate

      Issue actions

        CPM Patch step incorrectly assumes CMake external command is executed in shell, fails to apply multiple patches listed in `PATCHES` · Issue #651 · cpm-cmake/CPM.cmake