[CMake] Enable warnings

BlinkEye gentoo at blinkeye.ch
Mon Feb 25 05:53:16 EST 2008


On Mon, February 25, 2008 11:11, dizzy wrote:
> On Sunday 24 February 2008 23:22:58 blinkeye wrote:
>>  >> On 2/24/08, David Sveningsson <ext at sidvind.com> wrote:
>> >>
>> >> Hi, I'm quite new with cmake and I can't figure out how to enable
>> >> warnings for the generated makefiles/projects. For instance, I would
>> >> like to use the -Wall flag with gcc.
>>
>> like that for example:
>>
>> set( CMAKE_C_FLAGS   "-fstack-protector -fstack-protector-all" )
>> set( CMAKE_C_FLAGS_DEBUG   "-O2 -Wall -ggdb" )
>> set( CMAKE_C_FLAGS_RELEASE   "-Os -Wall" )
>>
>> set( CMAKE_CXX_FLAGS "-fstack-protector -fstack-protector-all" )
>> set( CMAKE_CXX_FLAGS_DEBUG "-O2 -Wall -ggdb" )
>> set( CMAKE_CXX_FLAGS_RELEASE "-Os -Wall" )
>
> That looks fairly unportable (how do you make sure your compiler supports
> those flags? if it doesn't it won't compile at all which is not probably what
> you want since you are using cmake I supose you want it portable).
>
> I prefer first to detect supported compiler arguments with
> CheckCXXCompilerFlag() and if yes add it to the CFLAGS of targets using
> SET_TARGET_PROPERTIES(target PROPERTIES COMPILE_FLAGS ...) (and if one wants
> to share several flags among many targets, put the flags in some variables
> and expand the variables in the SET_TARGET_PROPERTIES commands).
>
That's not very portable, true. But you understand the problem of the OP, do you?
He's new to cmake and he was asking on how to set compiler specific flags. Even
though your answers not wrong it doesn't help him at all. And no, cmake isn't used
just because it's portable.




More information about the CMake mailing list