I just don't seem to be able to wrap my head around CMake's escape rules. Given:
set(X A B C)
add_custom_target( works COMMAND DUMMY=0 X="${X}" env | grep ^X= COMMENT "This works")
add_custom_target( fails COMMAND X="${X}" env | grep ^X= COMMENT "This fails")
The intention is to execute command X="A B C" env
. The custom target works
correctly constructs the command, where as fails
incorrectly executes:
X=\"A B C\" env ...
But why?
Actually you ran into two problems:
COMMAND
is assumed to be a command name or file. So CMake tries to handle it as a single "string".So I changed the quoting and the
env
call and the following did work for me:For more details and possibilities see: