[CMake] spaces in generator strings troublesome

Konstantin Tokarev annulen at yandex.ru
Fri Nov 10 10:33:01 EST 2017



10.11.2017, 17:59, "stefan.waigand at continental-corporation.com" <stefan.waigand at continental-corporation.com>:
> 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.

Just  write your scripts in decent language which does not require multi-layer escaping:

#!/usr/bin/env perl
@cmdline = ('.', '-G', 'Unix Makefiles');
system 'cmake', @cmdline;

>
> 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
>
> ,--
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


-- 
Regards,
Konstantin


More information about the CMake mailing list