[cmake-developers] Unique compile definitions

Brad King brad.king at kitware.com
Fri Aug 17 09:07:13 EDT 2012


On 8/16/2012 11:42 AM, Stephen Kelly wrote:
> I thought that I could make -DNAME="value" appear twice with this code:
> 
>  add_definitions(-D"NAME=Value" -DNAME="Value")

CMake syntax treats quotes in the middle of an unquoted argument
literally.  The double quotes are part of the string.  This code:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmMakefile.cxx;hb=v2.8.9#l1269

does not recognize it as a definition flag.

> 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.

The code should be active if the value needs quoting on the
generated shell command line:

 set_property(TARGET foo PROPERTY COMPILE_DEFINITIONS "FOO=with space")

> 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.

The defines CMake knows about will be unique.  It is only the
raw -D flag that leaks through the above-linked code without
being recognized that might create a duplicate.  Rather than
try to handle the historical pre-quoted case and guess what
the user meant we should either make no change or just add
a warning for it.

-Brad



More information about the cmake-developers mailing list