[CMake] Enable warnings

Alexander Neundorf a.neundorf-work at gmx.net
Mon Feb 25 14:00:43 EST 2008


On Monday 25 February 2008, 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).

Or the simpler option:
if(CMAKE_COMPILER_IS_GNUCC)
... set gcc specific options


with cmake cvs/coming 2.6 you can do 

if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
... set gcc specific options

Alex



More information about the CMake mailing list