[CMake] Enable warnings

dizzy dizzy at roedu.net
Mon Feb 25 05:11:31 EST 2008


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

-- 
Mihai RUSU					Email: dizzy at roedu.net
			"Linux is obsolete" -- AST


More information about the CMake mailing list