Skip to content

Commit 6b6f596

Browse files
committed
Targets is no more, now default flags
1 parent baaad7a commit 6b6f596

File tree

8 files changed

+108
-105
lines changed

8 files changed

+108
-105
lines changed

tools/android.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import my_spawn
4+
import default_flags
45
from SCons.Script import ARGUMENTS
56

67

@@ -118,3 +119,5 @@ def generate(env):
118119
env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])
119120

120121
env.Append(CPPDEFINES=["ANDROID_ENABLED", "UNIX_ENABLED"])
122+
123+
default_flags.generate(env)

tools/targets.py renamed to tools/default_flags.py

Lines changed: 22 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
import os
22
import subprocess
33
import sys
4-
from SCons.Script import ARGUMENTS
5-
from SCons.Variables import *
6-
from SCons.Variables.BoolVariable import _text2bool
7-
84

95
# Helper methods
106

117

12-
def get_cmdline_bool(option, default):
13-
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
14-
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
15-
"""
16-
cmdline_val = ARGUMENTS.get(option)
17-
if cmdline_val is not None:
18-
return _text2bool(cmdline_val)
19-
else:
20-
return default
21-
22-
238
def using_clang(env):
249
return "clang" in os.path.basename(env["CC"])
2510

@@ -36,66 +21,34 @@ def is_vanilla_clang(env):
3621

3722

3823
# Main tool definition
39-
40-
41-
def options(opts):
42-
opts.Add(
43-
EnumVariable(
44-
"optimize",
45-
"The desired optimization flags",
46-
"speed_trace",
47-
("none", "custom", "debug", "speed", "speed_trace", "size"),
48-
)
49-
)
50-
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True))
51-
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
52-
53-
5424
def exists(env):
5525
return True
5626

5727

5828
def generate(env):
59-
# Configuration of build targets:
60-
# - Editor or template
61-
# - Debug features (DEBUG_ENABLED code)
62-
# - Dev only code (DEV_ENABLED code)
63-
# - Optimization level
64-
# - Debug symbols for crash traces / debuggers
65-
66-
# Keep this configuration in sync with SConstruct in upstream Godot.
67-
68-
env.editor_build = env["target"] == "editor"
69-
env.dev_build = env["dev_build"]
70-
env.debug_features = env["target"] in ["editor", "template_debug"]
71-
72-
if env.dev_build:
73-
opt_level = "none"
74-
elif env.debug_features:
75-
opt_level = "speed_trace"
76-
else: # Release
77-
opt_level = "speed"
78-
79-
env["optimize"] = ARGUMENTS.get("optimize", opt_level)
80-
env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
81-
82-
if env.editor_build:
83-
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
84-
85-
if env.debug_features:
86-
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
87-
# to give *users* extra debugging information for their game development.
88-
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
89-
# In upstream Godot this is added in typedefs.h when DEBUG_ENABLED is set.
90-
env.Append(CPPDEFINES=["DEBUG_METHODS_ENABLED"])
91-
92-
if env.dev_build:
93-
# DEV_ENABLED enables *engine developer* code which should only be compiled for those
94-
# working on the engine itself.
95-
env.Append(CPPDEFINES=["DEV_ENABLED"])
29+
# Require C++17
30+
if env.get("is_msvc", False):
31+
env.Append(CXXFLAGS=["/std:c++17"])
9632
else:
97-
# Disable assert() for production targets (only used in thirdparty code).
98-
env.Append(CPPDEFINES=["NDEBUG"])
33+
env.Append(CXXFLAGS=["-std=c++17"])
34+
35+
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
36+
# saves around 20% of binary size and very significant build time.
37+
if env["disable_exceptions"]:
38+
if env.get("is_msvc", False):
39+
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
40+
else:
41+
env.Append(CXXFLAGS=["-fno-exceptions"])
42+
elif env.get("is_msvc", False):
43+
env.Append(CXXFLAGS=["/EHsc"])
44+
45+
if not env.get("is_msvc", False):
46+
if env["symbols_visibility"] == "visible":
47+
env.Append(CCFLAGS=["-fvisibility=default"])
48+
env.Append(LINKFLAGS=["-fvisibility=default"])
49+
elif env["symbols_visibility"] == "hidden":
50+
env.Append(CCFLAGS=["-fvisibility=hidden"])
51+
env.Append(LINKFLAGS=["-fvisibility=hidden"])
9952

10053
# Set optimize and debug_symbols flags.
10154
# "custom" means do nothing and let users set their own optimization flags.

tools/godotcpp.py

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os, sys, platform
22

33
from SCons.Variables import EnumVariable, PathVariable, BoolVariable
4+
from SCons.Variables.BoolVariable import _text2bool
45
from SCons.Tool import Tool
56
from SCons.Builder import Builder
67
from SCons.Errors import UserError
8+
from SCons.Script import ARGUMENTS
9+
710

811
from binding_generator import scons_generate_bindings, scons_emit_files
912

@@ -14,6 +17,17 @@ def add_sources(sources, dir, extension):
1417
sources.append(dir + "/" + f)
1518

1619

20+
def get_cmdline_bool(option, default):
21+
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
22+
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
23+
"""
24+
cmdline_val = ARGUMENTS.get(option)
25+
if cmdline_val is not None:
26+
return _text2bool(cmdline_val)
27+
else:
28+
return default
29+
30+
1731
def normalize_path(val, env):
1832
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
1933

@@ -230,16 +244,23 @@ def options(opts, env):
230244
)
231245
)
232246

247+
opts.Add(
248+
EnumVariable(
249+
"optimize",
250+
"The desired optimization flags",
251+
"speed_trace",
252+
("none", "custom", "debug", "speed", "speed_trace", "size"),
253+
)
254+
)
255+
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True))
256+
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
257+
233258
# Add platform options (custom tools can override platforms)
234259
for pl in sorted(set(platforms + custom_platforms)):
235260
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
236261
if hasattr(tool, "options"):
237262
tool.options(opts)
238263

239-
# Targets flags tool (optimizations, debug symbols)
240-
target_tool = Tool("targets", toolpath=["tools"])
241-
target_tool.options(opts)
242-
243264

244265
def generate(env):
245266
# Default num_jobs to local cpu count if not user specified.
@@ -286,43 +307,56 @@ def generate(env):
286307

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

289-
if env.get("use_hot_reload") is None:
290-
env["use_hot_reload"] = env["target"] != "template_release"
291-
if env["use_hot_reload"]:
292-
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])
310+
# These defaults may be needed by platform tools
311+
env.use_hot_reload = env.get("use_hot_reload", env["target"] != "template_release")
312+
env.editor_build = env["target"] == "editor"
313+
env.dev_build = env["dev_build"]
314+
env.debug_features = env["target"] in ["editor", "template_debug"]
315+
316+
if env.dev_build:
317+
opt_level = "none"
318+
elif env.debug_features:
319+
opt_level = "speed_trace"
320+
else: # Release
321+
opt_level = "speed"
322+
323+
env["optimize"] = ARGUMENTS.get("optimize", opt_level)
324+
env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
293325

294326
tool = Tool(env["platform"], toolpath=get_platform_tools_paths(env))
295327

296328
if tool is None or not tool.exists(env):
297329
raise ValueError("Required toolchain not found for platform " + env["platform"])
298330

299331
tool.generate(env)
300-
target_tool = Tool("targets", toolpath=["tools"])
301-
target_tool.generate(env)
302-
303-
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
304-
# saves around 20% of binary size and very significant build time.
305-
if env["disable_exceptions"]:
306-
if env.get("is_msvc", False):
307-
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)])
308-
else:
309-
env.Append(CXXFLAGS=["-fno-exceptions"])
310-
elif env.get("is_msvc", False):
311-
env.Append(CXXFLAGS=["/EHsc"])
312-
313-
if not env.get("is_msvc", False):
314-
if env["symbols_visibility"] == "visible":
315-
env.Append(CCFLAGS=["-fvisibility=default"])
316-
env.Append(LINKFLAGS=["-fvisibility=default"])
317-
elif env["symbols_visibility"] == "hidden":
318-
env.Append(CCFLAGS=["-fvisibility=hidden"])
319-
env.Append(LINKFLAGS=["-fvisibility=hidden"])
320-
321-
# Require C++17
322-
if env.get("is_msvc", False):
323-
env.Append(CXXFLAGS=["/std:c++17"])
332+
333+
if env.use_hot_reload:
334+
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])
335+
336+
if env.editor_build:
337+
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
338+
339+
# Configuration of build targets:
340+
# - Editor or template
341+
# - Debug features (DEBUG_ENABLED code)
342+
# - Dev only code (DEV_ENABLED code)
343+
# - Optimization level
344+
# - Debug symbols for crash traces / debuggers
345+
# Keep this configuration in sync with SConstruct in upstream Godot.
346+
if env.debug_features:
347+
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
348+
# to give *users* extra debugging information for their game development.
349+
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
350+
# In upstream Godot this is added in typedefs.h when DEBUG_ENABLED is set.
351+
env.Append(CPPDEFINES=["DEBUG_METHODS_ENABLED"])
352+
353+
if env.dev_build:
354+
# DEV_ENABLED enables *engine developer* code which should only be compiled for those
355+
# working on the engine itself.
356+
env.Append(CPPDEFINES=["DEV_ENABLED"])
324357
else:
325-
env.Append(CXXFLAGS=["-std=c++17"])
358+
# Disable assert() for production targets (only used in thirdparty code).
359+
env.Append(CPPDEFINES=["NDEBUG"])
326360

327361
if env["precision"] == "double":
328362
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

tools/ios.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import subprocess
4+
import default_flags
45
from SCons.Variables import *
56

67
if sys.version_info < (3,):
@@ -104,3 +105,5 @@ def generate(env):
104105
env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]])
105106

106107
env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED"])
108+
109+
default_flags.generate(env)

tools/linux.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import default_flags
12
from SCons.Variables import *
23
from SCons.Tool import clang, clangxx
34

@@ -14,7 +15,7 @@ def generate(env):
1415
if env["use_llvm"]:
1516
clang.generate(env)
1617
clangxx.generate(env)
17-
elif env["use_hot_reload"]:
18+
elif env.use_hot_reload:
1819
# Required for extensions to truly unload.
1920
env.Append(CXXFLAGS=["-fno-gnu-unique"])
2021

@@ -37,3 +38,5 @@ def generate(env):
3738
env.Append(LINKFLAGS=["-march=rv64gc"])
3839

3940
env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"])
41+
42+
default_flags.generate(env)

tools/macos.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import default_flags
34

45

56
def has_osxcross():
@@ -70,3 +71,5 @@ def generate(env):
7071
)
7172

7273
env.Append(CPPDEFINES=["MACOS_ENABLED", "UNIX_ENABLED"])
74+
75+
default_flags.generate(env)

tools/web.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import default_flags
23
from SCons.Util import WhereIs
34

45

@@ -42,3 +43,5 @@ def generate(env):
4243
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])
4344

4445
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
46+
47+
default_flags.generate(env)

tools/windows.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
2-
32
import my_spawn
4-
3+
import default_flags
54
from SCons.Tool import msvc, mingw
65
from SCons.Variables import *
76

@@ -90,3 +89,5 @@ def generate(env):
9089
)
9190

9291
env.Append(CPPDEFINES=["WINDOWS_ENABLED"])
92+
93+
default_flags.generate(env)

0 commit comments

Comments
 (0)