From a3a3cafbc80256a691268862fb9906e838bc69dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 3 Jan 2025 22:38:38 +0100 Subject: [PATCH] SCons: Set explicit standards to C++98 and C11 Godot 1.0 was developed at a time where compilers defaulted to C++98. Also disable `-Wall` on debug builds, there are now hundreds of warnings from newer compilers that would need to be fixed. This would best be done by adding a new `warnings` SCons option, which would also affect non-debug builds, but I have no intention to fix warnings in the 1.0 branch, the goal here is just to get it to compile for archival and game preservation. (cherry picked from commit a68e96b8c2d88e01ff910b6e05631b50871ef0e0) --- SConstruct | 15 +++++++++++++++ platform/android/detect.py | 2 +- platform/flash/detect.py | 2 +- platform/iphone/detect.py | 6 +++--- platform/isim/detect.py | 4 ++-- platform/javascript/detect.py | 4 ++-- platform/nacl/detect.py | 2 +- platform/osx/detect.py | 2 +- platform/server/detect.py | 2 +- platform/windows/detect.py | 2 +- platform/x11/detect.py | 2 +- 11 files changed, 29 insertions(+), 14 deletions(-) diff --git a/SConstruct b/SConstruct index 11b35e0b4bb..58ad9117853 100644 --- a/SConstruct +++ b/SConstruct @@ -219,6 +219,21 @@ if selected_platform in platform_list: detect.configure(env) + # Set our C and C++ standard requirements. + # Prepending to make it possible to override. + # This MSVC "detection" is an extreme hack. + is_msvc = (os.name=="nt") and (os.getenv("VSINSTALLDIR")!=None or os.getenv("VCINSTALLDIR")!=None) and (selected_platform in ["windows", "winrt"]) + if (not is_msvc): + # Specifying GNU extensions support explicitly, which are supported by both GCC and Clang. + # We don't support C++17 so stick to earlier standards. + # Godot 1.0 definitely started as a C++98 codebase. + env.Prepend(CFLAGS=["-std=gnu11"]) + env.Prepend(CXXFLAGS=["-std=gnu++98"]) + # Disable these auto-enabled warnings which are treated as errors by modern compilers. + env.Prepend(CCFLAGS=["-Wno-error=implicit-function-declaration", "-Wno-error=incompatible-pointer-types"]) + else: + # MSVC doesn't support setting C++ to pre-C++14 standards, so do nothing and hope it works. + pass flag_list = platform_flags[selected_platform] for f in flag_list: diff --git a/platform/android/detect.py b/platform/android/detect.py index 5ef405f7b66..98637644698 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -150,7 +150,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-g1', '-Wall', '-O0', '-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-D_DEBUG', '-g1', '-O0', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) if env["armv6"] == "no" and env['x86'] != 'yes': diff --git a/platform/flash/detect.py b/platform/flash/detect.py index 5507ce5177d..48be88738bc 100644 --- a/platform/flash/detect.py +++ b/platform/flash/detect.py @@ -98,7 +98,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-g0', '-Wall', '-O0', '-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-D_DEBUG', '-g0', '-O0', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) env.Append(CPPFLAGS=['-DFLASH_ENABLED', '-DGLES1_ENABLED', '-DNO_FCNTL', '-DUNIX_ENABLED']) diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py index fb57876a838..de30d9f369b 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -109,17 +109,17 @@ def configure(env): if (env["target"]=="release"): - env.Append(CCFLAGS=['-O3', '-ffast-math', '-DNS_BLOCK_ASSERTIONS=1','-Wall']) + env.Append(CCFLAGS=['-O3', '-ffast-math', '-DNS_BLOCK_ASSERTIONS=1']) env.Append(LINKFLAGS=['-O3', '-ffast-math']) elif env["target"] == "release_debug": - env.Append(CCFLAGS=['-Os', '-ffast-math', '-DNS_BLOCK_ASSERTIONS=1','-Wall','-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-Os', '-ffast-math', '-DNS_BLOCK_ASSERTIONS=1','-DDEBUG_ENABLED']) env.Append(LINKFLAGS=['-Os', '-ffast-math']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ENABLED']) elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-Wall', '-O0', '-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ENABLED']) elif (env["target"]=="profile"): diff --git a/platform/isim/detect.py b/platform/isim/detect.py index bd0fd2fea3b..a99816f03e2 100644 --- a/platform/isim/detect.py +++ b/platform/isim/detect.py @@ -51,7 +51,7 @@ def configure(env): env['AR'] = 'ar' import string - env['CCFLAGS'] = string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fasm-blocks -Wall -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $ISIMSDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"') + env['CCFLAGS'] = string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $ISIMSDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"') env.Append(LINKFLAGS=['-arch', 'i386', '-mios-simulator-version-min=4.3', @@ -84,7 +84,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-DDEBUG', '-D_DEBUG', '-gdwarf-2', '-Wall', '-O0', '-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-DDEBUG', '-D_DEBUG', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) elif (env["target"]=="profile"): diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 947a637fb99..eaebef0fcac 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -73,8 +73,8 @@ def configure(env): elif (env["target"]=="release_debug"): env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-O2', '-DDEBUG_ENABLED']) - #env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-g4', '-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-D_DEBUG', '-O2', '-DDEBUG_ENABLED']) + #env.Append(CCFLAGS=['-D_DEBUG', '-g4', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) env.Append(CPPFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST','-fno-rtti']) diff --git a/platform/nacl/detect.py b/platform/nacl/detect.py index f8849cfd259..2acb59bb599 100644 --- a/platform/nacl/detect.py +++ b/platform/nacl/detect.py @@ -54,7 +54,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-g', '-O0', '-Wall','-DDEBUG_ENABLED']) + env.Append(CCFLAGS=['-g', '-O0', '-DDEBUG_ENABLED']) elif (env["target"]=="profile"): diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 5703cbc5465..97c841ca9f0 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -51,7 +51,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-g3', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + env.Append(CCFLAGS=['-g3', '-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) if (env["freetype"]!="no"): diff --git a/platform/server/detect.py b/platform/server/detect.py index e2d64c65458..c43f0a716ef 100644 --- a/platform/server/detect.py +++ b/platform/server/detect.py @@ -69,7 +69,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + env.Append(CCFLAGS=['-g2', '-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) env.Append(CPPFLAGS=['-DSERVER_ENABLED','-DUNIX_ENABLED']) env.Append(LIBS=['pthread','z']) #TODO detect linux/BSD! diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 298fa3bc789..3c125c91411 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -325,7 +325,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + env.Append(CCFLAGS=['-g', '-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) if (env["freetype"]!="no"): env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 7fa1666c59d..63389960551 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -121,7 +121,7 @@ def configure(env): elif (env["target"]=="debug"): - env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + env.Append(CCFLAGS=['-g2', '-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) env.ParseConfig('pkg-config x11 --cflags --libs') env.ParseConfig('pkg-config xinerama --cflags --libs')