[CMake] Why are blank-delimited strings in commands escaped on Linux?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Oct 2 05:09:08 EDT 2009


On 2009-10-02 06:26+0200 Andreas Pakulat wrote:

> On 01.10.09 18:18:24, Alan W. Irwin wrote:
>> This solution obviously reduces the urgency of the concern I expressed about
>> the motivation for escaping blanks for Linux because workarounds like above
>> can always be used.  However, I am still curious about what the motivation
>> is for escaping blanks for Linux commands.
>
> Because you have to escape spaces in arguments passed to a command.

The solution I came up with produced a VERBOSE=1 result that included

-L/usr/lib -lcairo

with no escaped blanks.  So there is obviously no necessity for escaping
blanks on the command line for this case.  So why does CMake insist on
always escaping them when you are using a blank-delimited string? Why not
take the string just as is with no escapes?


> Your
> misinterpreting "-Lx -ly" as a space-delimited list.

No.  I specifically used the phrase "blank-delimited string"
because there is no such thing as a "space-delimited list" in CMake.
And the question posed by the subject line still remains.

> So CMake just see's that you pass a
> _single_ argument consisting of the string >-Lx -ly< and properly quotes
> that string.

It is not that simple.  As far as I know, the _only_ case which has quotes
is if the string contains a blank and you specifically use quotes
(e.g., "${VARIABLE}") in the command for the no VERBATIM case or if you use
VERBATIM.

Also quoting and escaping are actually two separate issues (as you can see
for the no VERBATIM case where a unquoted variable consisting of a
blank-delimited string produces escaped blanks with no quotes, and an
unquoted variable consisting of a list produces ordinary delimiting blanks
with no quotes.)

>>  If that turns out to be a weak
>> motivation (i.e., replacing escaped blanks with ordinary delimiting blanks
>> causes little harm and helps a lot for most situations) perhaps it is time
>> to change CMake policy on this so that workarounds like above to avoid
>> escaped blanks on Linux will not be needed in the future.
>
> Its not a workaround, if you want to pass a list of arguments to an
> external command you have to create a CMake list. A string containing a
> list of arguments won't work unless the arguments are delimited by ; which
> implicitly makes the string a list.

The reason why the blank-delimited string doesn't work is the blanks are
escaped by CMake.  Otherwise, it would be fine.

As you know, I did try converting my blank-delimited string to a list, and
that actually worked with no VERBATIM to produce a VERBOSE=1 command that
included

-L/usr/lib -lcairo

with no quotes which is exactly what I wanted.  If that were surrounded by
quotes (as I think you get with the VERBATIM case), that should not work
since those are two command-line options (which happen to be stored
in a blank-delimited string) and not one.

However, the question posed by my subject line still remains. There is
probably a good reason why blank-delimited strings have their blanks escaped
on the Linux command line, but I would like to know what it is because I
haven't seen such a good reason yet.

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