[cmake-developers] Unique compile definitions

Stephen Kelly steveire at gmail.com
Thu Aug 16 11:42:13 EDT 2012


Brad King wrote:

> On 08/13/2012 09:09 AM, Stephen Kelly wrote:
>> I uploaded a compromise compile-definitions-unique branch to my gitorious
>> (git at gitorious.org:~steveire/cmake/steveires-
cmake.git)
>> which stores the unescaped definition in the set, and escapes it in the
>> JoinDefines method.
> 
> Even better, thanks.

I have not yet merged this to next yet because I thought that in its current 
form, it might not create really unique defines. On further investigation I 
might have found some dead code.

Reading this comment:

      // Make the definition appear properly on the command line.  Use
      // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.

I thought that I could make -DNAME="value" appear twice with this code:

 add_definitions(-D"NAME=Value" -DNAME="Value")

I found that not only does it not de-duplicate, it does 
not convert -D"NAME=Value" to -DNAME="Value", as I expected from the 
comment. It turns out that the -D"NAME=Value" does not get as far as the 
AppendDefines method, and is treated as a raw flag, not a define:

build{master}$ cat CMakeFiles/foo.dir/flags.make 
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/lib/icecc/bin/c++
CXX_FLAGS =   -D"NAME=Value"

CXX_DEFINES = -DNAME=\"Value\"


This might be intentional, but then the code in AppendDefines is dead and 
should be removed. If it is unintentional, then I have found a bug.

There is still Watcom escaping which I did not test though. As the current 
patch stores unescaped defines, the escaped defines may not be unique. I 
could fix it with another std::set and loop in JoinDefines (maybe just if 
WatcomWMake, depending on whether the above is a bug or not). Is it worth 
it?

Thanks,

Steve.






More information about the cmake-developers mailing list