[CMake] Tricky problem with variable, whitespace, quotes and shell

Asmodehn Shade asmodehn at gmail.com
Tue Aug 11 04:10:10 EDT 2009


Well I need to have the quotes in there to keep the space in between the
filenames, otherwise they all get replaced by a ";" semi colon, as per cmake
behaviour to set a list ( cmake list are ";" separated )

Anyway it seems I managed to work around the problem by adding another level
of shell :

First I put the whole command in quotes :
SET( cmdline "${ASTYLE_EXECUTABLE} --style=ansi ${SPACES_SOURCES}")
this way the quotes around the sources filenames disappear... eaten by the
quotes for the whole string

Then I add my custom target :
ADD_CUSTOM_TARGET(format ALL sh -c ${cmdline} VERBATIM )
the sh -c runs another shell who can now evaluate the command in quotes
completely without being annoyed by the quotes in there...

Seems to work fine so far...

Hope this post will be useful to others ;-)

--
AlexV

2009/8/7 Tyler Roscoe <tyler at cryptio.net>

On Thu, Aug 06, 2009 at 08:04:37PM +0900, Asmodehn Shade wrote:
> > there fore I use the trick here which gives me the correct solution :
> >
> http://www.vtk.org/Wiki/CMake_FAQ#How_to_convert_a_semicolon_separated_list_to_a_whitespace_separated_string.3F
> >
> > So now SPACES_SOURCES holds : "filea.c fileb.c"
> >
> > however now I want to use that in a custom target  :
> > ADD_CUSTOM_TARGET(format ALL ${ASTYLE_EXECUTABLE} --style=ansi
> > ${SPACES_SOURCES} VERBATIM )
> >
> > Problem is that the command generated by cmake still includes the  double
> > quotes.
> > therefore : astyle --style=ansi "filea.c fileb.c" doesnt work ( expects
> one
> > file with a space in the name )
>
> Are you somehow introducing the quotes to SPACES_SOURCES while doing the
> list expansion? ${ASTYLE_EXECUTABLE} doesn't have the same problem, so
> I'm guessing you got them in there somehow.
>
> tyler
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090811/4b2e5c02/attachment-0001.htm>


More information about the CMake mailing list