I have the following command to download a tar.gz file, unpack it, and apply a patch file:
FetchContent_Populate(${PROJECT_NAME} URL ${url}
PATCH_COMMAND patch -p1 < ${PROJECT_SOURCE_DIR}/mumps-nag.patch)
This works as expected with cmake 3.27.7. But with version 3.30.5 it fails with the following error:
patching file '<'
Hunk #1 FAILED at 51.
patch: **** Can't reopen file '<' : No such file or directory
It appears that ‘<’ is being interpreted as a file name rather than redirecting stdin from the file. Has something intentional changed between 3.27.7 and 3.30.5? In another project we use the same kind of PATCH_COMMAND but inside an externalproject_add
and it works fine there with 3.30.5. I’m stumped.
Commands in FetchContent and ExternalProject are not guaranteed to be executed using any particular shell, or even any shell at all. You’re relying on <
being treated as a redirection operator by a shell, but that has never been safe to do, nor guaranteed to work. Put your command in a script and run that script instead if it needs to use shell features. Even better, you can invoke the patch
command with appropriate command line options such that you don’t need the <
operator at all.
There have been a lot of changes with FetchContent in the last couple of CMake feature releases. Your example looks like it has been taken from a project rather than a CMake script file. The FetchContent documentation explicitly states that the form of FetchContent_Populate()
you’re using should only be used in CMake script mode, and CMake 3.30 deprecated the other (single-argument) form of FetchContent_Populate()
altogether (see CMP0169). If you’ve updated your project’s policy settings, you might also be seeing an effect of CMP0168, although this seems less likely.
Thanks for the detailed explanation. Yes this was from a project (from someone else) that I need to modify. I know what I need to do now, thanks!