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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Dec 1 21:39:12 EST 2008


On 2008-12-01 18:55-0500 Brad King wrote:

> Alan W. Irwin wrote:

[...]
>> 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. [...]

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

Shouldn't that be up to the user to insert quotes where needed in the
command rather than CMake anticipating their needs (incorrectly in this
case)?

Thus, I suggest you implement a VERBATIM that means pass the original form
of command exactly as specified in the CMakeLists.txt file (except for CMake
variable substitution) without any extra quotes (or anything else) being
inserted.  Quotes are pretty powerful shell operators so I don't see why
CMake should ever insert extra ones. If CMake has the capability of keeping
track of the original form of COMMAND (or reproducing it) the implementation
should be trivial.

> 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?

I just found a pretty good bash tutorial on redirection
(http://bash-hackers.org/wiki/doku.php?id=howto:redirection_tutorial).

I assume you already have at least "<", ">", and "|" in the list and from
the tutorial it appears you should add in at least (">&", "2>", "1>", and
"2>&1") as well. But I frankly don't understand why a list is necessary to
eliminate the quotes that CMake inserts when you use VERBATIM.
(see question above and comment below).

>
>> Regardless of that bug question, is there a way to work around this CMake
>> issue?
>
> Don't use VERBATIM.

Thanks very much for that suggestion.

Indeed, that works for the following test case:

project(test_redirection NONE)
cmake_minimum_required(VERSION 2.6)
add_custom_target(test_target cat /dev/null >& /dev/null)

The generated command is

cat /dev/null >& /dev/null

However, just to give a simple test case illustrating the original
issue, if I use

project(test_redirection NONE)
cmake_minimum_required(VERSION 2.6)
add_custom_target(test_target cat /dev/null >& /dev/null VERBATIM)

the generated command is

cat /dev/null ">&" /dev/null

which, of course, generates errors.

So VERBATIM inserts quotes while if you don't specify VERBATIM, then the
generated command is exactly the same as you specified.  That's confusing
(at least to me) since that behaviour is contrary to the normal English
meaning of "verbatim".

The 2.6.2 documentation implies you should use VERBATIM except for old
projects so that is why I adopted it in this particular case. Also, I
assumed that dropping VERBATIM would add even more unwanted stuff to the
COMMAND so I didn't try that until you suggested it.  Anyhow, I am very glad
of this (drop VERBATIM keyword) workaround for now, but I also hope you
implement a change so that VERBATIM never inserts quotes in the generated
COMMAND.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list