Skip to content

Commit 1443d02

Browse files
committed
Allow building using a custom godot-cpp verison
You can use it with: scons godot_cpp=/path/to/godot-cpp This commit also forces the new "disable_exceptions" godot cpp option to false since exceptions are needed by libdatachannel, and makes sure to always compile/link with dynamic runtime when using MSVC.
1 parent 431df32 commit 1443d02

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

SConstruct

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@ def replace_flags(flags, replaces):
2020
flags[flags.index(k)] = v
2121

2222

23+
def validate_godotcpp_dir(key, val, env):
24+
normalized = val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
25+
if not os.path.isdir(normalized):
26+
raise UserError("GDExtension directory ('%s') does not exist: %s" % (key, val))
27+
28+
2329
env = Environment()
2430
opts = Variables(["customs.py"], ARGUMENTS)
2531
opts.Add(EnumVariable("godot_version", "The Godot target version", "4.1", ["3", "4.0", "4.1"]))
32+
opts.Add(
33+
PathVariable(
34+
"godot_cpp",
35+
"Path to the directory containing Godot CPP folder",
36+
None,
37+
validate_godotcpp_dir,
38+
)
39+
)
2640
opts.Update(env)
2741

2842
# Minimum target platform versions.
@@ -33,11 +47,15 @@ if "macos_deployment_target" not in ARGUMENTS:
3347
if "android_api_level" not in ARGUMENTS:
3448
ARGUMENTS["android_api_level"] = "28"
3549

50+
# Recent godot-cpp versions disables exceptions by default, but libdatachannel requires them.
51+
ARGUMENTS["disable_exceptions"] = "no"
52+
3653
if env["godot_version"] == "3":
3754
if "platform" in ARGUMENTS and ARGUMENTS["platform"] == "macos":
3855
ARGUMENTS["platform"] = "osx" # compatibility with old osx name
3956

40-
cpp_env = SConscript("godot-cpp-3.x/SConstruct")
57+
sconstruct = env.get("godot_cpp", "godot-cpp-3.x") + "/SConstruct"
58+
cpp_env = SConscript(sconstruct)
4159

4260
# Patch base env
4361
replace_flags(
@@ -105,9 +123,18 @@ if env["godot_version"] == "3":
105123
for flags in (env["CCFLAGS"], env["LINKFLAGS"], cpp_env["CCFLAGS"], cpp_env["LINKFLAGS"]):
106124
replace_flags(flags, {"-m32": None, "-m64": None})
107125
elif env["godot_version"] == "4.0":
108-
env = SConscript("godot-cpp-4.0/SConstruct").Clone()
126+
sconstruct = env.get("godot_cpp", "godot-cpp-4.0") + "/SConstruct"
127+
cpp_env = SConscript(sconstruct)
128+
env = cpp_env.Clone()
109129
else:
110-
env = SConscript("godot-cpp/SConstruct").Clone()
130+
sconstruct = env.get("godot_cpp", "godot-cpp") + "/SConstruct"
131+
cpp_env = SConscript(sconstruct)
132+
env = cpp_env.Clone()
133+
134+
if cpp_env.get("is_msvc", False):
135+
# Make sure we don't build with static cpp on MSVC (default in recent godot-cpp versions).
136+
replace_flags(env["CCFLAGS"], {"/MT": "/MD"})
137+
replace_flags(cpp_env["CCFLAGS"], {"/MT": "/MD"})
111138

112139
# Should probably go to upstream godot-cpp.
113140
# We let SCons build its default ENV as it includes OS-specific things which we don't

0 commit comments

Comments
 (0)