[CMake] Visual Studio 8 and warning levels

Sylvain Benner benner at virtools.com
Fri Sep 28 05:30:12 EDT 2007


> I'm having some trouble getting a clean way to set the warning level
> in my projects with Visual Studio 2005.
>
> When I try this
> SET(CMAKE_C_WARNING_LEVEL 4)
> SET(CMAKE_CXX_WARNING_LEVEL 4)
>
> It seems to be ignored because the project files still have the
> warning level set to 3.  I only want to turn up (or down) the warning
> level for particular projects so I don't want to mess with the cache
> variable.
>
> I found this searching through old posts and it works, but it seems a
> bit sloppy to have to do this when there is a simply way to just set
> the Warning Level.
>
> IF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
>      STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
> ELSE(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
>      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
> ENDIF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
>
> -Neal
To modify the compiler flags you must alter the CMAKE_CXX_FLAGS. It's 
the same thing for the linker flags.
But feel free to create macros to hide all this stuff yo your users :)

--Sylvain


More information about the CMake mailing list