Discussion:
[Cmake] How to remove a #define?
Mathews, Rob
2003-09-22 17:32:40 UTC
Permalink
The CMake documentation says that you do this

ADD_DEFINITIONS - Add -D define flags to command line for environments.
Usage: ADD_DEFINITIONS(-DFOO -DBAR ...) Add -D define flags to command line
for environments.

to define a variable for the preprocessor. I'm wondering how you do the
reverse - how to undefine an variable for the preprocessor.

FYI, I've got an example where I want
a default of "UNICODE" defined for all the projects, except
in this particular subdir, where I don't want UNICODE
defined.

My environment is .NET 2003.

Is there any way to do this?
Andy Cedilnik
2003-09-22 17:48:59 UTC
Permalink
Hi Rob,

Unfortunately there is no way to remove -D right now. You can be more
selective when you add it though. Look through "Defining a variable for
the compiler in one directory only" thread for doing that. That said, I
did add a feature request to the CMake bug tracker.

Andy
Post by Mathews, Rob
The CMake documentation says that you do this
ADD_DEFINITIONS - Add -D define flags to command line for environments.
Usage: ADD_DEFINITIONS(-DFOO -DBAR ...) Add -D define flags to command line
for environments.
to define a variable for the preprocessor. I'm wondering how you do the
reverse - how to undefine an variable for the preprocessor.
FYI, I've got an example where I want
a default of "UNICODE" defined for all the projects, except
in this particular subdir, where I don't want UNICODE
defined.
My environment is .NET 2003.
Is there any way to do this?
Brad King
2003-09-23 14:13:54 UTC
Permalink
Post by Mathews, Rob
ADD_DEFINITIONS - Add -D define flags to command line for environments.
Usage: ADD_DEFINITIONS(-DFOO -DBAR ...) Add -D define flags to command
line for environments.
You can try this, but I haven't tested it:

ADD_DEFINITIONS(-UFOO -UBAR)

-Brad
Mathews, Rob
2003-09-23 17:39:39 UTC
Permalink
I tried it. It seems to work, although it would probably be a cleaner
.vcproj file if the generator for .NET understood that "-U" natively.

At least, a trivial example line:

ADD_DEFINITIONS("-DFOO")
ADD_DEFINITIONS("-UFOO")
ADD_EXECUTABLE(test_cmake test.cpp)

does result in FOO being undefined while compiling test.cpp.

Rob.
-----Original Message-----
Sent: Tuesday, September 23, 2003 10:14 AM
To: Mathews, Rob
Subject: Re: [Cmake] How to remove a #define?
Post by Mathews, Rob
ADD_DEFINITIONS - Add -D define flags to command line for
environments.
Post by Mathews, Rob
Usage: ADD_DEFINITIONS(-DFOO -DBAR ...) Add -D define flags
to command
Post by Mathews, Rob
line for environments.
ADD_DEFINITIONS(-UFOO -UBAR)
-Brad
Mathews, Rob
2003-09-23 20:43:48 UTC
Permalink
And of course it fails as soon as you use a real-world example. For example,


ADD_DEFINITIONS(-DUNICODE -D_UNICODE -DWIN32 -Di386 -D_WIN32_WINNT=0x501 )
ADD_DEFINITIONS("-UUNICODE")
ADD_EXECUTABLE(test_cmake test.cpp)

Gives you an interesting error at compile time when the _WIN32_WINNT macro
is expanded and is considered to include "-UUNICODE" as part of its value.

However, the following *hack* does happen work:

ADD_DEFINITIONS(-DUNICODE -D_UNICODE -DWIN32 -Di386 -D_WIN32_WINNT=0x501 )
ADD_DEFINITIONS(",-UUNICODE")
ADD_EXECUTABLE(test_cmake test.cpp)

Note the magic "," - it actually seems to cause .NET to consider the
following words as a new command line argument.

Rob.
-----Original Message-----
From: Mathews, Rob
Sent: Tuesday, September 23, 2003 1:40 PM
To: 'Brad King'; Mathews, Rob
Subject: RE: [Cmake] How to remove a #define?
I tried it. It seems to work, although it would probably be a
cleaner .vcproj file if the generator for .NET understood
that "-U" natively.
ADD_DEFINITIONS("-DFOO")
ADD_DEFINITIONS("-UFOO")
ADD_EXECUTABLE(test_cmake test.cpp)
does result in FOO being undefined while compiling test.cpp.
Rob.
-----Original Message-----
Sent: Tuesday, September 23, 2003 10:14 AM
To: Mathews, Rob
Subject: Re: [Cmake] How to remove a #define?
Post by Mathews, Rob
ADD_DEFINITIONS - Add -D define flags to command line for
environments.
Post by Mathews, Rob
Usage: ADD_DEFINITIONS(-DFOO -DBAR ...) Add -D define flags
to command
Post by Mathews, Rob
line for environments.
ADD_DEFINITIONS(-UFOO -UBAR)
-Brad
Brad King
2003-09-23 20:50:41 UTC
Permalink
Post by Mathews, Rob
And of course it fails as soon as you use a real-world example. For
example,
ADD_DEFINITIONS(-DUNICODE -D_UNICODE -DWIN32 -Di386 -D_WIN32_WINNT=0x501 )
ADD_DEFINITIONS("-UUNICODE")
ADD_EXECUTABLE(test_cmake test.cpp)
Gives you an interesting error at compile time when the _WIN32_WINNT
macro is expanded and is considered to include "-UUNICODE" as part of
its value.
Not surprising. You may want to try a different approach altogether. We
recommend not using ADD_DEFINITIONS at all and instead using configured
header files. See this message:

http://www.cmake.org/pipermail/cmake/2003-September/004286.html

-Brad

Loading...