-
-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SCons] Refactor targets, symbols, optimizations.
Now matches Godot `master` target names and supports the same flags with the following notable exceptions: - The default target is "template_debug", since it's compatible with editor builds (and TOOLS_ENABLED is never used internally). - separate_debug_symbols is still not supported, and will be done in a separate commit.
- Loading branch information
Showing
8 changed files
with
107 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
include/gen | ||
src/gen | ||
|
||
# Build configuarion. | ||
/custom.py | ||
|
||
# Misc | ||
logs/* | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,88 @@ | ||
import os | ||
import sys | ||
from SCons.Script import ARGUMENTS | ||
from SCons.Variables import * | ||
from SCons.Variables.BoolVariable import _text2bool | ||
|
||
|
||
def get_cmdline_bool(option, default): | ||
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line, | ||
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings. | ||
""" | ||
cmdline_val = ARGUMENTS.get(option) | ||
if cmdline_val is not None: | ||
return _text2bool(cmdline_val) | ||
else: | ||
return default | ||
|
||
|
||
def options(opts): | ||
opts.Add( | ||
EnumVariable( | ||
"optimize", | ||
"The desired optimization flags", | ||
"auto", | ||
("auto", "none", "debug", "speed", "size", "0", "1", "2", "3"), | ||
"speed_trace", | ||
("none", "custom", "debug", "speed", "speed_trace", "size"), | ||
) | ||
) | ||
opts.Add(BoolVariable("debug_symbols", "Add debugging symbols to release builds", False)) | ||
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True)) | ||
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", 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" | ||
env.dev_build = env["dev_build"] | ||
env.debug_features = env["target"] in ["editor", "template_debug"] | ||
env.editor_build = env["target"] == "editor" | ||
|
||
if env.editor_build: | ||
env.AppendUnique(CPPDEFINES=["TOOLS_ENABLED"]) | ||
|
||
if env.debug_features: | ||
env.AppendUnique(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"]) | ||
|
||
if env.dev_build: | ||
opt_level = "none" | ||
env.AppendUnique(CPPDEFINES=["DEV_ENABLED"]) | ||
elif env.debug_features: | ||
opt_level = "speed_trace" | ||
else: # Release | ||
opt_level = "speed" | ||
|
||
env["optimize"] = ARGUMENTS.get("optimize", opt_level) | ||
env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build) | ||
|
||
if "is_msvc" in env and env["is_msvc"]: | ||
if env["debug_symbols"]: | ||
env.Append(CCFLAGS=["/Z7", "/D_DEBUG"]) | ||
env.Append(CCFLAGS=["/Zi", "/FS"]) | ||
env.Append(LINKFLAGS=["/DEBUG:FULL"]) | ||
else: | ||
env.Append(CCFLAGS=["/Z7", "/DNDEBUG"]) | ||
|
||
if env["optimize"] == "speed": | ||
if env["optimize"] == "speed" or env["optimize"] == "speed_trace": | ||
env.Append(CCFLAGS=["/O2"]) | ||
env.Append(LINKFLAGS=["/OPT:REF"]) | ||
elif env["optimize"] == "size": | ||
env.Append(CCFLAGS=["/Os"]) | ||
elif env["optimize"] == "debug": | ||
env.Append(CCFLAGS=["/Od"]) | ||
elif env["optimize"] == "none": | ||
env.Append(CCFLAGS=["/O1"]) | ||
env.Append(LINKFLAGS=["/OPT:REF"]) | ||
elif env["optimize"] == "debug" or 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.dev_build: | ||
env.Append(CCFLAGS=["-g3"]) | ||
else: | ||
env.Append(CCFLAGS=["-g2"]) | ||
|
||
if env["optimize"] == "speed": | ||
env.Append(CCFLAGS=["-O3"]) | ||
# `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces. | ||
elif env["optimize"] == "speed_trace": | ||
env.Append(CCFLAGS=["-O2"]) | ||
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"]]) |