[CMake] Ensuring spaces in CFLAGS reach Visual Studio project files

Clifford Yapp cliffyapp at gmail.com
Fri Dec 17 17:54:55 EST 2010


I have a situation where I need to pass strings with spaces in them as
definitions in CFLAGS, e.g.

SET(CMAKE_C_CFLAGS  -DINPUT_STRING=\\\"first\\ second\\\"")

This is NOT working for Visual Studio, which is apparently quite picky
about this - it apparently needs to end up with something like:

INPUT_STRING="\"first second\""

I can duplicate the "\" quote structure part (VERY ugly -
\\\"\\\\\\\") but I'm getting stopped cold by the space between first
and second.  I've tried quoting variations, and while I can preserve
the space as far as CMake's definition in the cache, the results that
get written into the Visual Studio file ALWAYS seem to break on the
space, quoted or not.  e.g. I get:

INPUT_STRING="\"first

or

INPUT_STRING="\"first\

etc.

For variable definitions I might be able to live with not using a
space, but some of the arguments I have to pass in are pathnames with
spaces.  That's user controlled - I HAVE to be able to handle it, or
in the worst case impose the limitation of no spaces in pathnames on
Windows (ouch).

Can someone tell me how to quote a space such that it ends up included
in the preprocessor definition line in a Visual Studio project?

Cheers,
CY


More information about the CMake mailing list