[CMake] spaces in generator strings troublesome
Michael Ellery
mellery451 at gmail.com
Fri Nov 10 11:30:46 EST 2017
> On Nov 10, 2017, at 6:49 AM, Stefan.Waigand at continental-corporation.com wrote:
>
> Hello,
>
> the usual way to pass a generator string to the cmake executable on the command line is:
> cmake . -G"Unix Makefiles"
>
> But when i have some bash scripting around it and try to hold the command line arguments in a variable, the trouble begins...
>
> export CMDLINE=". -G\"Unix Makefiles\"" && cmake $CMDLINE
> -> CMake Error: Could not create named generator "Unix
>
> The reason seems to be bash separates arguments by spaces, and does not care for the quotes.
>
> I tried to escape the space character somehow, but nothing seems to help:
>
> export CMDLINE=". -G\"Unix\ Makefiles\"" && cmake $CMDLINE
> -> CMake Error: Could not create named generator "Unix\
>
> export CMDLINE=". -G'Unix Makefiles'" && cmake $CMDLINE
> -> CMake Error: Could not create named generator 'Unix
>
> Now there might be ways how to work around this in bash. E.g. by quoting arguments on their own as done here
> https://stackoverflow.com/questions/42111441/how-to-pass-command-line-arguments-with-spaces-through-a-variable-in-bash
> or here
> https://unix.stackexchange.com/questions/108635/why-i-cant-escape-spaces-on-a-bash-script
> But this is more complicated, harder to understand and maintain - not a nice solution.
>
> Looking around, i do not seem to be alone with this kind of problem. Example https://stackoverflow.com/questions/20570042/calling-cmake-with-bash-variable-argument
>
> So here is my plea to the CMake developers and feature request:
> Could you please let CMake support this kind of command line?
> cmake . -GUnix_Makefiles
>
> i mean besides the established way CMake should accept the generator strings with '_' instead of ' '?
> If the command line parser could replace '_' by ' ' things would be backward compatible, right?
> This would solve problems as mentioned above and help people to automate their CMake environments.
>
> Thank you,
> Stefan
perhaps handle arguments as an array variable in bash - it’s a slightly saner way to deal with args with spaces:
CMDLINE=(. -G"Unix Makefiles") && cmake "${CMDLINE[@]}”
-Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171110/a6704995/attachment.sig>
More information about the CMake
mailing list