Shell compound commands in add_custom_command() possible?

Hi,

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

Stupid example (which does not work):

add_custom_command(
    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
Ingolf

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.
Ingolf