my project warnlevel is /w3. I want to enable as single warning from warnlevel 4. Such as "C4296 'operator' : expression is always false"
How can I do this in cxx flags of my CMake file?
my project warnlevel is /w3. I want to enable as single warning from warnlevel 4. Such as "C4296 'operator' : expression is always false"
How can I do this in cxx flags of my CMake file?
Just add to your main CMakeLists.txt
(CMake version >= 2.8.12) generally
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34296>")
or (thanks @tambre for the hint) just to a specific target
target_add_compile_options(MyTarget "$<$<CXX_COMPILER_ID:MSVC>:/w34296>")
The shwon generator expression will add warning C4296 to warning level 3 for MSVC
compilers (for the VC warning options see link provided by @Richard Critten)
Some more possibilities for setting compile option with CMake in Visual Studio projects can be found in my answer given here.
This code works for me.
#enable compiler warning C4296 in warnlevel 3
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w34296 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w34296 ")