[CMake] Different CMAKE_CXX_FLAGS for different executables

Michael Hertling mhertling at online.de
Wed Mar 30 08:11:10 EDT 2011


On 03/25/2011 03:36 PM, David Doria wrote:
>> Could you post the output of "make VERBOSE=1"?
>>
>> On *nix, the following CMakeLists.txt works as expected:
>> The output of "make VERBOSE=1" contains:
>>
>>> .../c++ -DUNIX -o .../SetTargetProperties.cxx.o -c .../SetTargetProperties.cxx
> 
> It is working properly now. I must not have done a 'make clean'.
> 
>> BTW, preprocessor definitions like "-DUNIX" should be set via the
>> COMPILE_DEFINITIONS properties instead of the COMPILE_FLAGS ones.
> 
> It seems to generate exactly the same thing if I use
> 
> set_target_properties(CompilerFlags PROPERTIES COMPILE_FLAGS "-DUNIX")
> 
> and
> 
> set_target_properties(CompilerFlags PROPERTIES COMPILE_DEFINITIONS "UNIX")
> 
> After reading the documentation you set certainly sounds like I should
> use the COMPILE_DEFINITIONS version, but is there a difference?
> 
> Thanks again,
> 
> David

For simple defines, i.e. without "=" sign, COMPILE_FLAGS with "-D" and
COMPILE_DEFINITIONS without "-D" should act equivalently. However, the
latter cares about the correct escaping for more complex definitions,
i.e. -DXYZ=\"...\" and the like. Furthermore, COMPILE_DEFINITIONS has
configuration-specific variants and is also available as a directory
property. Finally, it is list-oriented while COMPILE_FLAGS is space-
separated. Thus, COMPILE_DEFINITIONS is preferable for preprocessor
definitions while COMPILE_FLAGS should be reserved for non-define
flags - as long as it doesn't become obsolete anyway due to the
envisaged COMPILE_OPTIONS property [1].

Regards,

Michael

[1] http://public.kitware.com/Bug/view.php?id=6493#c13821


More information about the CMake mailing list