SCons: Fix MSVC bypassing disabled warnings

This commit is contained in:
Thaddeus Crews 2024-12-08 15:58:14 -06:00
parent aa8d9b83f6
commit 070aeb5688
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
7 changed files with 55 additions and 67 deletions

View File

@ -815,37 +815,36 @@ elif env.msvc:
# Configure compiler warnings # Configure compiler warnings
if env.msvc and not methods.using_clang(env): # MSVC if env.msvc and not methods.using_clang(env): # MSVC
if env["warnings"] == "no": # Disable warnings which we don't plan to fix.
env.Append(CCFLAGS=["/w"]) disabled_warnings = [
else: "/wd4100", # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
if env["warnings"] == "extra": "/wd4127", # C4127 (conditional expression is constant)
env.Append(CCFLAGS=["/W4"]) "/wd4201", # C4201 (non-standard nameless struct/union): Only relevant for C89.
elif env["warnings"] == "all": "/wd4244", # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
# C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too. "/wd4245",
env.Append(CCFLAGS=["/W3", "/w34458"]) "/wd4267",
elif env["warnings"] == "moderate": "/wd4305", # C4305 (truncation): double to float or real_t, too hard to avoid.
env.Append(CCFLAGS=["/W2"]) "/wd4324", # C4820 (structure was padded due to alignment specifier)
# Disable warnings which we don't plan to fix. "/wd4514", # C4514 (unreferenced inline function has been removed)
"/wd4714", # C4714 (function marked as __forceinline not inlined)
"/wd4820", # C4820 (padding added after construct)
]
env.Append( if env["warnings"] == "extra":
CCFLAGS=[ env.Append(CCFLAGS=["/W4"] + disabled_warnings)
"/wd4100", # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism. elif env["warnings"] == "all":
"/wd4127", # C4127 (conditional expression is constant) # C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too.
"/wd4201", # C4201 (non-standard nameless struct/union): Only relevant for C89. env.Append(CCFLAGS=["/W3", "/w34458"] + disabled_warnings)
"/wd4244", # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale. elif env["warnings"] == "moderate":
"/wd4245", env.Append(CCFLAGS=["/W2"] + disabled_warnings)
"/wd4267", else: # 'no'
"/wd4305", # C4305 (truncation): double to float or real_t, too hard to avoid. # C4267 is particularly finicky & needs to be explicitly disabled.
"/wd4324", # C4820 (structure was padded due to alignment specifier) env.Append(CCFLAGS=["/w", "/wd4267"])
"/wd4514", # C4514 (unreferenced inline function has been removed)
"/wd4714", # C4714 (function marked as __forceinline not inlined)
"/wd4820", # C4820 (padding added after construct)
]
)
if env["werror"]: if env["werror"]:
env.Append(CCFLAGS=["/WX"]) env.Append(CCFLAGS=["/WX"])
env.Append(LINKFLAGS=["/WX"]) env.Append(LINKFLAGS=["/WX"])
else: # GCC, Clang else: # GCC, Clang
common_warnings = [] common_warnings = []

View File

@ -58,7 +58,7 @@
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(disable : 4189 4324 4505) #pragma warning(disable : 4189 4505)
#endif #endif
#include "thirdparty/d3d12ma/D3D12MemAlloc.cpp" #include "thirdparty/d3d12ma/D3D12MemAlloc.cpp"

View File

@ -130,9 +130,10 @@ def disable_warnings(self):
if self.msvc and not using_clang(self): if self.msvc and not using_clang(self):
# We have to remove existing warning level defines before appending /w, # We have to remove existing warning level defines before appending /w,
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'" # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))] WARN_FLAGS = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/W0"]
self["CFLAGS"] = [x for x in self["CFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))] self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in WARN_FLAGS]
self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))] self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in WARN_FLAGS]
self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in WARN_FLAGS]
self.AppendUnique(CCFLAGS=["/w"]) self.AppendUnique(CCFLAGS=["/w"])
else: else:
self.AppendUnique(CCFLAGS=["-w"]) self.AppendUnique(CCFLAGS=["-w"])

View File

@ -31,17 +31,22 @@ thirdparty_sources = [
] ]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_csg.Prepend( env_csg.Prepend(CPPPATH=[thirdparty_dir + "include"])
CPPPATH=[
thirdparty_dir + "include",
]
)
env_thirdparty = env_csg.Clone() env_thirdparty = env_csg.Clone()
env_thirdparty.disable_warnings() env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.modules_sources += thirdparty_obj env.modules_sources += thirdparty_obj
# Godot's own source files # Godot source files
env_csg.add_source_files(env.modules_sources, "*.cpp")
module_obj = []
env_csg.add_source_files(module_obj, "*.cpp")
if env.editor_build: if env.editor_build:
env_csg.add_source_files(env.modules_sources, "editor/*.cpp") env_csg.add_source_files(module_obj, "editor/*.cpp")
env.modules_sources += module_obj
# Needed to force rebuilding the module files when the thirdparty library is updated.
env.Depends(module_obj, thirdparty_obj)

View File

@ -77,17 +77,13 @@ def disable_warnings(self):
if self["platform"] == "windows" and not self["use_mingw"]: if self["platform"] == "windows" and not self["use_mingw"]:
# We have to remove existing warning level defines before appending /w, # We have to remove existing warning level defines before appending /w,
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'" # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
warn_flags = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/WX"] WARN_FLAGS = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/W0"]
self.Append(CCFLAGS=["/w"]) self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in WARN_FLAGS]
self.Append(CFLAGS=["/w"]) self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in WARN_FLAGS]
self.Append(CXXFLAGS=["/w"]) self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in WARN_FLAGS]
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in warn_flags] self.AppendUnique(CCFLAGS=["/w"])
self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in warn_flags]
self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in warn_flags]
else: else:
self.Append(CCFLAGS=["-w"]) self.AppendUnique(CCFLAGS=["-w"])
self.Append(CFLAGS=["-w"])
self.Append(CXXFLAGS=["-w"])
def make_icu_data(target, source, env): def make_icu_data(target, source, env):

View File

@ -77,17 +77,13 @@ def disable_warnings(self):
if self["platform"] == "windows" and not self["use_mingw"]: if self["platform"] == "windows" and not self["use_mingw"]:
# We have to remove existing warning level defines before appending /w, # We have to remove existing warning level defines before appending /w,
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'" # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
warn_flags = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/WX"] WARN_FLAGS = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/W0"]
self.Append(CCFLAGS=["/w"]) self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in WARN_FLAGS]
self.Append(CFLAGS=["/w"]) self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in WARN_FLAGS]
self.Append(CXXFLAGS=["/w"]) self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in WARN_FLAGS]
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in warn_flags] self.AppendUnique(CCFLAGS=["/w"])
self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in warn_flags]
self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in warn_flags]
else: else:
self.Append(CCFLAGS=["-w"]) self.AppendUnique(CCFLAGS=["-w"])
self.Append(CFLAGS=["-w"])
self.Append(CXXFLAGS=["-w"])
def make_icu_data(target, source, env): def make_icu_data(target, source, env):

View File

@ -35,17 +35,8 @@
#include "core/os/os.h" #include "core/os/os.h"
#include "scene/resources/image_texture.h" #include "scene/resources/image_texture.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127)
#endif
#include "thirdparty/misc/yuv2rgb.h" #include "thirdparty/misc/yuv2rgb.h"
#ifdef _MSC_VER
#pragma warning(pop)
#endif
int VideoStreamPlaybackTheora::buffer_data() { int VideoStreamPlaybackTheora::buffer_data() {
char *buffer = ogg_sync_buffer(&oy, 4096); char *buffer = ogg_sync_buffer(&oy, 4096);