diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-11 19:25:22 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-12 16:52:05 +0200 |
commit | 2bf983e6382f5236948f7740faf130a3568f9dd0 (patch) | |
tree | 6e877051c4b419eee813aabcd47f77129bfcf00c /tools | |
parent | 024b6d2d9e6bb6ed8b2c1641330ae444e6c6ba7a (diff) | |
download | redot-cpp-2bf983e6382f5236948f7740faf130a3568f9dd0.tar.gz |
[SCons] Add "optimize" and "debug_symbols" options
optimize = auto|none|debug|speed|size|0|1|2|3
debug_symbol = True|False
optimize == "auto" will produce:
- "debug" for "debug" builds
- "speed" for "release" builds
Diffstat (limited to 'tools')
-rw-r--r-- | tools/android.py | 7 | ||||
-rw-r--r-- | tools/ios.py | 5 | ||||
-rw-r--r-- | tools/linux.py | 5 | ||||
-rw-r--r-- | tools/macos.py | 5 | ||||
-rw-r--r-- | tools/targets.py | 57 | ||||
-rw-r--r-- | tools/windows.py | 11 |
6 files changed, 64 insertions, 26 deletions
diff --git a/tools/android.py b/tools/android.py index e96f9e6..720ff2d 100644 --- a/tools/android.py +++ b/tools/android.py @@ -96,11 +96,6 @@ def generate(env): env.Append( CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"] - ) # , '-fPIE', '-fno-addrsig', '-Oz']) + ) env.Append(CCFLAGS=arch_info["ccflags"]) env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]]) - - if env["target"] == "debug": - env.Append(CCFLAGS=["-Og", "-g"]) - elif env["target"] == "release": - env.Append(CCFLAGS=["-O3"]) diff --git a/tools/ios.py b/tools/ios.py index 71ac5b5..11d606b 100644 --- a/tools/ios.py +++ b/tools/ios.py @@ -79,8 +79,3 @@ def generate(env): env.Append(CCFLAGS=["-isysroot", env["IOS_SDK_PATH"]]) env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]]) - - if env["target"] == "debug": - env.Append(CCFLAGS=["-Og", "-g"]) - elif env["target"] == "release": - env.Append(CCFLAGS=["-O3"]) diff --git a/tools/linux.py b/tools/linux.py index df8a78e..099a048 100644 --- a/tools/linux.py +++ b/tools/linux.py @@ -18,11 +18,6 @@ def generate(env): env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"]) env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"]) - if env["target"] == "debug": - env.Append(CCFLAGS=["-Og", "-g"]) - elif env["target"] == "release": - env.Append(CCFLAGS=["-O3"]) - if env["arch"] == "x86_64": # -m64 and -m32 are x86-specific already, but it doesn't hurt to # be clear and also specify -march=x86-64. Similar with 32-bit. diff --git a/tools/macos.py b/tools/macos.py index 57e9d7f..2e4bfc6 100644 --- a/tools/macos.py +++ b/tools/macos.py @@ -48,8 +48,3 @@ def generate(env): "-Wl,-undefined,dynamic_lookup", ] ) - - if env["target"] == "debug": - env.Append(CCFLAGS=["-Og", "-g"]) - elif env["target"] == "release": - env.Append(CCFLAGS=["-O3"]) diff --git a/tools/targets.py b/tools/targets.py new file mode 100644 index 0000000..f13979d --- /dev/null +++ b/tools/targets.py @@ -0,0 +1,57 @@ +import os +import sys +from SCons.Variables import * + + +def options(opts): + opts.Add( + EnumVariable( + "optimize", + "The desired optimization flags", + "auto", + ("auto", "none", "debug", "speed", "size", "0", "1", "2", "3"), + ) + ) + opts.Add(BoolVariable("debug_symbols", "Add debugging symbols to release builds", False)) + + +def exists(env): + return True + + +def generate(env): + if env["optimize"] == "auto": + env["optimize"] = "speed" if env["target"] == "release" else "debug" + env["debug_symbols"] = env["debug_symbols"] or env["target"] == "debug" + + if "is_msvc" in env and env["is_msvc"]: + if env["debug_symbols"]: + env.Append(CCFLAGS=["/Z7", "/D_DEBUG"]) + env.Append(LINKFLAGS=["/DEBUG:FULL"]) + else: + env.Append(CCFLAGS=["/Z7", "/DNDEBUG"]) + + if env["optimize"] == "speed": + env.Append(CCFLAGS=["/O2"]) + elif env["optimize"] == "size": + env.Append(CCFLAGS=["/Os"]) + elif env["optimize"] == "debug": + env.Append(CCFLAGS=["/Od"]) + elif env["optimize"] == "none": + env.Append(CCFLAGS=["/Od"]) + else: + env.Append(CCFLAGS=["/O%s" % env["optimize"]]) + else: + if env["debug_symbols"]: + env.Append(CCFLAGS=["-g"]) + + if env["optimize"] == "speed": + env.Append(CCFLAGS=["-O3"]) + elif env["optimize"] == "size": + env.Append(CCFLAGS=["-Os"]) + elif env["optimize"] == "debug": + env.Append(CCFLAGS=["-Og"]) + elif env["optimize"] == "none": + env.Append(CCFLAGS=["-O0"]) + else: + env.Append(CCFLAGS=["-O%s" % env["optimize"]]) diff --git a/tools/windows.py b/tools/windows.py index 3d5d22e..c4cbf79 100644 --- a/tools/windows.py +++ b/tools/windows.py @@ -25,12 +25,13 @@ def generate(env): env["is_msvc"] = True msvc.generate(env) env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"]) + env.Append(CCFLAGS=["/EHsc"]) env.Append(LINKFLAGS=["/WX"]) - if env["target"] == "debug": - env.Append(CCFLAGS=["/Z7", "/Od", "/EHsc", "/D_DEBUG", "/MDd"]) - env.Append(LINKFLAGS=["/DEBUG:FULL"]) - elif env["target"] == "release": - env.Append(CCFLAGS=["/O2", "/EHsc", "/DNDEBUG", "/MD"]) + if env["debug_symbols"] or env["target"] == "debug": + env.Append(CCFLAGS=["/MDd"]) + else: + env.Append(CCFLAGS=["/MD"]) + if env["use_clang_cl"]: env["CC"] = "clang-cl" env["CXX"] = "clang-cl" |