[CMake] VS Warning Level Compiler Flag

Brad King brad.king at kitware.com
Fri Oct 1 07:04:05 EDT 2004


Marco Spatz wrote:
> Hi,
> 
> I'm using cmake to create a VS 7.1 project using OpenSG. The Warning 
> Level flag is automatically set to /W3, but this gives my a lot of 
> warnings in the OpenSG libraries (seems to be ok, checked their mailing 
> list). So I want to lower the warning level to /W1, but I don't know how 
> to do that in CMake. Already tried to use the
> ADD_DEFINITIOINS(-DW1) and other variations, but this setting always is 
> ignored.
> 
> Can someone help?

VTK raises the warning level to /W4 like this:

IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
   # Use the highest warning level for visual studio.
   SET(CMAKE_CXX_WARNING_LEVEL 4)
   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]")
ENDIF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")

Just replace /W4 with /W1 and set CMAKE_CXX_WARNING_LEVEL to 1.

-Brad


More information about the CMake mailing list