[CMake] 2.6.0 ADD_DEFINITIONS()

Bill Hoffman bill.hoffman at kitware.com
Tue May 6 21:35:32 EDT 2008


David Blado wrote:
> Congratulations to the CMake team for getting this awaited release to
> the community!
> 
> I have a quick question regarding preprocessor definitions being escaped
> automatically.  In CMake < 2.4, I would use:
> 
> ADD_DEFINITIONS(-D_U_=\"__attribute__\(\(used\)\)\")
> 
> To tell gcc that I wanted to use _U_ in my code to prevent the compiler
> from optimizing something out of my binary.
> 
> I'm getting a warning in CMake 2.6.0 saying that I no longer need to
> escape like above.  So I tried:
> 
> ADD_DEFINITIONS(-D_U_=__attribute__((used)))
> 
> And got from CMake: Parse error.  Function missing ending ")".  Instead
> found left paren with text "(".
> 
> How should I format my ADD_DEFINITIONS(-D_U_=__attribute__((used))) to
> work properly in CMake 2.6.0 w/out a warning?
>
This seems to work:

cmake_minimum_required(VERSION 2.6)
add_definitions("-D_U_=__attribute__((used))")
add_library(foo foo.c)

It produces (no warnings):

C_DEFINES = -D"_U_=__attribute__((used))"

-Bill


More information about the CMake mailing list