CMake ignores "Treat warnings as errors" (/WX) when generating Windows projects

Viewed 1550

My CMake version is 3.18.0-rc2. In my project's CMakeLists.txt I have the following lines which are supposed to crank up the warning levels and treat all warnings as errors:

if(MSVC)
    add_compile_options(/W4 /WX)
    add_link_options(/W4 /WX)
else()
    add_compile_options(-Wall -Wextra -pedantic -Werror -Wl,--fatal-warnings)
endif()

I've only been able to test things out on Windows so far - the non-MSVC options are there for if/when we try to compile on other platforms in future.

When I generate Visual Studio projects with CMake and check the settings, the warning level is appropriately set to /W4, but /WX is not enabled - it is set to /WX- instead.

I know that add_compile_options() is having an effect because if I change the warning level to something else (/W3, for instance), I see this reflected in the project settings. However, it appears that no matter what I do, /WX is not respected. Is there a way I can fix this?

0 Answers
Related