[CMake] Getting rid of unwanted quotes that CMake inserts into commands

Brad King brad.king at kitware.com
Mon Dec 1 18:55:21 EST 2008


Alan W. Irwin wrote:
> I have defined the following custom command:
> 
> add_custom_command(
>   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grid_EOS1_2.out
>   COMMAND ${free_eos_test_LOCATION} < 
> ${CMAKE_CURRENT_BINARY_DIR}/grid_EOS1_2.in >& 
> ${CMAKE_CURRENT_BINARY_DIR}/grid_EOS1_2.out
>   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grid_EOS1_2.in free_eos_test
>   VERBATIM
>   )
> 
> The COMMAND line will get wrapped in this e-mail, but it appears all in one
> line in the CMakeLists.txt file.
> 
> For both 2.6.1 and 2.6.2, the resulting command that is executed is fine
> except that >& is transformed to ">&" and those inserted double quotes
> interfere with the desired redirection. If I use > instead (which makes
> stderr default to the terminal rather than mixing it in with 
> grid_EOS1_2.out
> like I would like), then there are no double quotes surrounding that in the
> generated command.  If I use 2> and 1> redirection to generate two files
> (one for stderr, one for stdout), they are transformed to "2>" and "1>" by
> CMake and those inserted double quotes again interfere with the desired
> redirection.
> 
> Is this a CMake bug (since double quotes are being inserted into the
> generated command for >&, 2>, and 1> despite the VERBATIM above)?

It can be considered a bug or a feature.  VERBATIM means literally 
verbatim, as in "pass these exact options and avoid all shell 
translation".  Originally even the normal redirections were escaped too. 
  In 2.6 we added some special cases for common (basic) redirections. 
We can add more.  Are you aware of a complete list of redirection 
operators that work in all make shells?

> Regardless of that bug question, is there a way to work around this CMake
> issue?

Don't use VERBATIM.  Alternatively, create your own script or helper 
program to do the redirecion.

-Brad


More information about the CMake mailing list