Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove env.get logic from defaults #1289

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def options(opts, env):
EnumVariable(
key="platform",
help="Target platform",
default=env.get("platform", default_platform),
default=default_platform,
allowed_values=platforms,
ignorecase=2,
)
Expand All @@ -99,60 +99,60 @@ def options(opts, env):
EnumVariable(
key="target",
help="Compilation target",
default=env.get("target", "template_debug"),
default="template_debug",
allowed_values=("editor", "template_release", "template_debug"),
)
)
opts.Add(
PathVariable(
key="gdextension_dir",
help="Path to a custom directory containing GDExtension interface header and API JSON file",
default=env.get("gdextension_dir", None),
default=None,
validator=validate_dir,
)
)
opts.Add(
PathVariable(
key="custom_api_file",
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
default=env.get("custom_api_file", None),
default=None,
validator=validate_file,
)
)
opts.Add(
BoolVariable(
key="generate_bindings",
help="Force GDExtension API bindings generation. Auto-detected by default.",
default=env.get("generate_bindings", False),
default=False,
)
)
opts.Add(
BoolVariable(
key="generate_template_get_node",
help="Generate a template version of the Node class's get_node.",
default=env.get("generate_template_get_node", True),
default=True,
)
)
opts.Add(
BoolVariable(
key="build_library",
help="Build the godot-cpp library.",
default=env.get("build_library", True),
default=True,
)
)
opts.Add(
EnumVariable(
key="precision",
help="Set the floating-point precision level",
default=env.get("precision", "single"),
default="single",
allowed_values=("single", "double"),
)
)
opts.Add(
EnumVariable(
key="arch",
help="CPU architecture",
default=env.get("arch", ""),
default="",
allowed_values=architecture_array,
map=architecture_aliases,
)
Expand All @@ -163,14 +163,14 @@ def options(opts, env):
BoolVariable(
key="compiledb",
help="Generate compilation DB (`compile_commands.json`) for external tools",
default=env.get("compiledb", False),
default=False,
)
)
opts.Add(
PathVariable(
key="compiledb_file",
help="Path to a custom `compile_commands.json` file",
default=env.get("compiledb_file", "compile_commands.json"),
default="compile_commands.json",
validator=validate_parent_dir,
)
)
Expand All @@ -179,13 +179,15 @@ def options(opts, env):
BoolVariable(
key="use_hot_reload",
help="Enable the extra accounting required to support hot reload.",
default=(env.get("target", "template_debug") != "template_release"),
default=None,
)
)

opts.Add(
BoolVariable(
"disable_exceptions", "Force disabling exception handling code", default=env.get("disable_exceptions", True)
key="disable_exceptions",
help="Force disabling exception handling code",
default=True,
)
)

Expand Down Expand Up @@ -245,19 +247,11 @@ def generate(env):

print("Building for architecture " + env["arch"] + " on platform " + env["platform"])

if not env.get("use_hot_reload"):
env["use_hot_reload"] = env["target"] != "template_release"
if env["use_hot_reload"]:
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])

# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time.
if env["disable_exceptions"]:
if env.get("is_msvc", False):
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
else:
env.Append(CXXFLAGS=["-fno-exceptions"])
elif env.get("is_msvc", False):
env.Append(CXXFLAGS=["/EHsc"])

tool = Tool(env["platform"], toolpath=["tools"])

if tool is None or not tool.exists(env):
Expand All @@ -267,8 +261,18 @@ def generate(env):
target_tool = Tool("targets", toolpath=["tools"])
target_tool.generate(env)

# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time.
if env["disable_exceptions"]:
if env["is_msvc"]:
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
else:
env.Append(CXXFLAGS=["-fno-exceptions"])
elif env["is_msvc"]:
env.Append(CXXFLAGS=["/EHsc"])

# Require C++17
if env.get("is_msvc", False):
if env["is_msvc"]:
env.Append(CXXFLAGS=["/std:c++17"])
else:
env.Append(CXXFLAGS=["-std=c++17"])
Expand Down Expand Up @@ -333,7 +337,7 @@ def _godot_cpp(env):
default_args = [library]

# Add compiledb if the option is set
if env.get("compiledb", False):
if env["compiledb"]:
default_args += ["compiledb"]

env.Default(*default_args)
Expand Down
4 changes: 3 additions & 1 deletion tools/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def generate(env):

# Set optimize and debug_symbols flags.
# "custom" means do nothing and let users set their own optimization flags.
if env.get("is_msvc", False):
if not env.get("is_msvc"):
env["is_msvc"] = False
if env["is_msvc"]:
if env["debug_symbols"]:
env.Append(CCFLAGS=["/Zi", "/FS"])
env.Append(LINKFLAGS=["/DEBUG:FULL"])
Expand Down