Shell compound commands in add_custom_command() possible?


is it possible to use shell compound commands as COMMAND in add_custom_command()?

Stupid example (which does not work):

    OUTPUT fobar.txt
    COMMAND ( echo "foo" ; echo "bar" ) > foobar.txt

I have already tried several combinations of COMMAND_EXPAND_LISTS, VERBATIM and quoting/escaping – up to now without success (using CMake 3.21.3). Any hints?

Kind regards

Custom commands make no guarantees about what shell they run in, if any. If you really need shell behavior, invoke a shell explicitly and pass the command to run inside it. Or better still, put it in a shell script and run that as the command.

Thanks a lot for the clarification.