[CMake] add_definition??

Michael Hertling mhertling at online.de
Mon Apr 18 00:04:04 EDT 2011


On 04/14/2011 06:56 AM, Michael Wild wrote:
> On 04/13/2011 11:50 PM, klaas.holwerda wrote:
>> Hi,
>>
>> I use ADD_DEFINITIONS( ${wxWidgets_DEFINITIONS} ) to add flags for
>> compilation like this:
>>
>>     set( wxWidgets_CXX_FLAGS ${wxWidgets_CXX_FLAGS}
>>         -D__WXMSW__ -D__GNUWIN32__ -D__WIN95__
>>         -fexceptions -fno-pcc-struct-return
>>         -fstrict-aliasing
>>         -Wall    #all warnings
>>         -Wno-unused-variable
>>          )
>>
>> Now a user complains that those flags are added to CXX_FLAGS as well as
>> RC_FLAGS .
>> The first is right, the second is a problem for the resource compiler
>> windres.exe used in codeblocks IDE.
>>
>> What is the right way to set compiler flags for cpp sources and other
>> flags for the resource compiler?
>>
>> Or are the generated makefiles not correct??
>>
>> Thanks,
>>
>> Klaas
> 
> If you think about the name of the function, adding anything but
> preprocessor definitions is just plain wrong. Append them to the
> CMAKE_CXX_FLAGS variable instead.
> 
> Michael

One might also add non-define compilation flags with ADD_DEFINITIONS(),
but they'll apply to all compilations in the current directory and its
subdirectories, i.e. to rc/windres compilations, too, AFAIK. Thus, the
job - or the art - is to distribute compilation flags and preprocessor
definitions on the CMAKE_{CXX,RC,...}_FLAGS variables, COMPILE_FLAGS
target/source properties and COMPILE_DEFINITIONS directory/target/
source properties in an appropriate manner.

Regards,

Michael


More information about the CMake mailing list