2
0
Эх сурвалжийг харах

Rework warning levels

Now you have: extra, all (the default), moderate, no.
The old 'yes' option is still supported, but a warning will be printed and 'all' will be assumed.

The different options will translate to the following:

MSVC:
extra -> /Wall (implies /W4)
all -> /W3 + disable non-essential (*)
moderate -> /W2 + disable non-essential (*)
no -> /w

GCC/Clang:
extra -> -Wall -Wextra
all -> -Wall
moderate -> -Wall -Wno-unused
no -> -w

* = Truncations, narrowing conversions...: /wd4267 /wd4244 /wd4305 /wd4800
Pedro J. Estébanez 8 жил өмнө
parent
commit
49669c9b42
1 өөрчлөгдсөн 22 нэмэгдсэн , 10 устгасан
  1. 22 10
      SConstruct

+ 22 - 10
SConstruct

@@ -145,7 +145,7 @@ opts.Add('extra_suffix', "Custom extra suffix added to the base filename of all
 opts.Add('unix_global_settings_path', "UNIX-specific path to system-wide settings. Currently only used for templates", '')
 opts.Add('verbose', "Enable verbose output for the compilation (yes/no)", 'yes')
 opts.Add('vsproj', "Generate Visual Studio Project. (yes/no)", 'no')
-opts.Add('warnings', "Enable showing warnings during the compilation (yes/no)", 'yes')
+opts.Add('warnings', "Set the level of warnings emitted during compilation (extra/all/moderate/no)", 'all')
 
 # Thirdparty libraries
 opts.Add('builtin_freetype', "Use the builtin freetype library (yes/no)", 'yes')
@@ -276,16 +276,28 @@ if selected_platform in platform_list:
     # must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11)
     detect.configure(env)
 
-    # TODO: Add support to specify different levels of warning, e.g. only critical/significant, instead of on/off
-    if (env["warnings"] == "yes"):
-        if (os.name == "nt" and os.getenv("VSINSTALLDIR")): # MSVC, needs to stand out of course
-            env.Append(CCFLAGS=['/W4'])
-        else: # Rest of the world
-            env.Append(CCFLAGS=['-Wall'])
-    else:
-        if (os.name == "nt" and os.getenv("VSINSTALLDIR")): # MSVC
+    if (env["warnings"] == 'yes'):
+        print("WARNING: warnings=yes is deprecated; assuming warnings=all")
+
+    if (os.name == "nt" and os.getenv("VSINSTALLDIR")): # MSVC, needs to stand out of course
+        disable_nonessential_warnings = ['/wd4267', '/wd4244', '/wd4305', '/wd4800'] # Truncations, narrowing conversions...
+        if (env["warnings"] == 'extra'):
+            env.Append(CCFLAGS=['/Wall']) # Implies /W4
+        elif (env["warnings"] == 'all' or env["warnings"] == 'yes'):
+            env.Append(CCFLAGS=['/W3'] + disable_nonessential_warnings)
+        elif (env["warnings"] == 'moderate'):
+            # C4244 shouldn't be needed here being a level-3 warning, but it is
+            env.Append(CCFLAGS=['/W2'] + disable_nonessential_warnings)
+        else: # 'no'
             env.Append(CCFLAGS=['/w'])
-        else: # Rest of the world
+    else: # Rest of the world
+        if (env["warnings"] == 'extra'):
+            env.Append(CCFLAGS=['-Wall', '-Wextra'])
+        elif (env["warnings"] == 'all' or env["warnings"] == 'yes'):
+            env.Append(CCFLAGS=['-Wall'])
+        elif (env["warnings"] == 'moderate'):
+            env.Append(CCFLAGS=['-Wall', '-Wno-unused'])
+        else: # 'no'
             env.Append(CCFLAGS=['-w'])
 
     #env['platform_libsuffix'] = env['LIBSUFFIX']