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

Asmodehn Shade asmodehn at gmail.com
Thu Aug 6 07:10:40 EDT 2009


Ah I forgot to say also...

I cant put the whole command line in quotes, otherwise the add_custom_target
tells me
"/bin/sh : command not found "<whole command line including parameters....>
"

so I need to separate the command executable and its parameter, but then the
command gets parameters with quotes and fails...

---
AlexV ... puzzled...

2009/8/6 Asmodehn Shade <asmodehn at gmail.com>

> Hi everyone,
>
> Sorry if this has been answered before, but google doesnt give me anything
> useful...
>
> Lets say I have a list of source files : SOURCES holds : filea.c;fileb.c
> I want to pass them to an external program ( Astyle for example ) so I need
> to have a whitespace separated list
>
> 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 )
>
> I cant even use a first shell to evaluate those because cmake would escape
> the single reverse quotes :
> astyle --style=ansi \` echo "filea.c fileb.c"\`
> which is the exact opposite of what I want...
>
> Any idea anyone ? I guess I must be missing something obvious here, but
> this has troubled me for a while now...
>
> Thanks a lot !
>
> --
> Alex
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090806/34ee4013/attachment.htm>


More information about the CMake mailing list