[CMake] add_definitions & "string" values
Filip Brcic
brcha at users.sourceforge.net
Tue Jun 12 13:44:40 EDT 2007
Дана уторак 12 јун 2007, Alexander Neundorf је написао(ла):
> On Tuesday 12 June 2007 12:38, Welter Luigi Silva wrote:
> > Hi again,
> > I'm trying to have a definition with a string value, say, "foo".
> > However, when I tried the following command:
> >
> > add_definitions(-DFOO="foo")
> >
> > and used FOO in my source file -- in a command like printf("%s\n", FOO)
> > -- I got 'foo' without the quotes, which is not a valid string literal,
> > as I wished it was.
> > I've also tried the command bellow but it did not work as well:
> > add_definitions(-DFOO="\"foo\"")
>
> You need more escaping, the following should work:
> add_definitions(-DFOO=\\"foo\\")
Yes, and for increased readability, I would suggest you to use:
add_definitions(-DFOO="\\"foo\\"")
so that you get
gcc -DFOO="\"foo\"" yourfile.c
when CMake compiles your file and, obviously, FOO="foo" in C.
On the sidenote, how does that relate to various shells? I'm using bash, but
did anybody cases with escapes like this one in other shells such as csh,
zsh, {,d}ash, or Micro$oft's favourite - ksh?
Filip
--
Filip Brcic <brcha at users.sourceforge.net>
WWWeb: http://purl.org/NET/brcha/home/
Jabber: brcha at kdetalk.net
Jabber: brcha at elitesecurity.org
Jabber: fbrcic at gmail.com
ICQ# 40994923
Yahoo! brcha
MSN: brcha at users.sourceforge.net
More information about the CMake
mailing list