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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Oct 2 04:13:43 EDT 2009


On 2009-10-02 08:58+0200 Hendrik Sattler wrote:

> Zitat von "Alan W. Irwin" <irwin at beluga.phys.uvic.ca>:
>> [Use]
>> string(REGEX REPLACE " " ";" CAIRO_LINK_FLAGS_LIST "${CAIRO_LINK_FLAGS}")
>> [to convert a blank-delimited string to a list].
>
> Doing this REGEX REPLACE cannot be the recommended way as that breaks any 
> paths that contain spaces. Doesn't
> set(CAIRO_LINK_FLAGS_LIST ${CAIRO_LINK_FLAGS})
> also make this a list but honors a possible quoting and escaping? (Note: no 
> extra quoting in the above line).

Hi Hendrik:

I can never figure out such things 100 per cent from documentation.  Instead
I try a simple test such as

set(a "hello world\\ hello world")
message(STATUS "a = ${a}")
set(a_list ${a})
message(STATUS "a_list = ${a_list}")

The result is

-- a = hello world\ hello world
-- a_list = hello world\ hello world

IOW, your idea (which I actually thought might work) does not appear to
convert a blank-delimited string to a list.

Your concern about breaking blank-containing paths is valid in general, but
in this specific case we are almost certainly okay since the result is the
link flags for libcairo as delivered by pkg-config.  I have no idea what
pkg-config would do if the path name of libcairo (which I agree in theory
could be anything since people build and install their own versions to any
location they like) contained spaces.  But assuming pkg-config worked in
this case, would it deliver "-L/path/with /blanks -lcairo" or "-L/path/with\
/blanks -lcairo" to the CMake variable? I think you would have to do
something really special in CMake to deal with this case.  I frankly don't
think the effort would be worth it, and it would just be easier to tell
users of the PLplot build system on Linux not to use a cairo installation
prefix with a blank in the name (if anyone actually ever tried that which I
doubt they would).

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