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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Oct 1 21:18:24 EDT 2009


On 2009-10-01 19:51-0400 Bill Lorensen wrote:

> I think if you specify each arg as a string it should work as expected.
> "-L/usr/lib" "-lcairo"

To generalize that idea, I have discovered since my post that if I
transform the blank delimited string CAIRO_LINK_FLAGS (which happens to be
filled with "-L/usr/lib -lcairo" in this case)

to a list, e.g.,

string(REGEX REPLACE " " ";" CAIRO_LINK_FLAGS_LIST "${CAIRO_LINK_FLAGS}")

then

COMMAND ocamlmklib <options> ${CAIRO_LINK_FLAGS_LIST} <more options>

transforms to the "make VERBOSE=1" command

ocamlmklib <options> -L/usr/lib -lcairo <more options>

i.e., the escaped blank I was getting before has been replaced by an
ordinary delimiting blank. Perfect!

This was for the case when VERBATIM was not specified.  I have not
investigated what happens for the VERBATIM case, but I think the imposed 
double quotes around -L/usr/lib -lcairo that I believe would happen for that
case would not work since the shell does have to treat the -L/usr/lib option
separately from the -lcairo option for the ocmalmklib command.

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

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