[CMAKE] Turn all warnings into errors on MSVC x86
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 21 Feb 2020 19:07:27 +0000 (20:07 +0100)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 23 Jul 2021 20:03:48 +0000 (22:03 +0200)
sdk/cmake/msvc.cmake

index e6b533a..f32f88c 100644 (file)
@@ -88,6 +88,22 @@ add_compile_options(/wd4244 /wd4290 /wd4800 /wd4200 /wd4214)
 # FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113
 add_compile_options(/wd4018)
 
+# Allow all warnings on msbuild/VS IDE
+if (MSVC_IDE)
+    set(ALLOW_WARNINGS TRUE)
+endif()
+
+# On x86 Debug builds, if it's not Clang-CL or msbuild, treat all warnings as errors
+if ((ARCH STREQUAL "i386") AND (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT USE_CLANG_CL) AND (NOT MSVC_IDE))
+    set(TREAT_ALL_WARNINGS_AS_ERRORS=TRUE)
+endif()
+
+# Define ALLOW_WARNINGS=TRUE on the cmake/configure command line to bypass errors
+if (ALLOW_WARNINGS)
+    # Nothing
+elseif (TREAT_ALL_WARNINGS_AS_ERRORS)
+    add_compile_options(/WX)
+else()
 # The following warnings are treated as errors:
 # - C4013: implicit function declaration
 # - C4020: too many actual parameters
@@ -119,6 +135,8 @@ if(MSVC_IDE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
     add_compile_options(/we4101 /we4189)
 endif()
 
+endif()
+
 # Enable warnings above the default level, but don't treat them as errors:
 # - C4115: named type definition in parentheses
 add_compile_options(/w14115)
@@ -194,8 +212,8 @@ if (NOT MSVC_IDE)
 endif()
 
 if(_VS_ANALYZE_)
-    message("VS static analysis enabled!")
-    add_compile_options(/analyze)
+    message("-- VS static analysis enabled!")
+    add_compile_options(/analyze:WX-)
 elseif(_PREFAST_)
     message("PREFAST enabled!")
     set(CMAKE_C_COMPILE_OBJECT "prefast <CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <INCLUDES> <FLAGS> <DEFINES> /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"