@@ -20,9 +20,23 @@ def replace_flags(flags, replaces):
20
20
flags [flags .index (k )] = v
21
21
22
22
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
+
23
29
env = Environment ()
24
30
opts = Variables (["customs.py" ], ARGUMENTS )
25
31
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
+ )
26
40
opts .Update (env )
27
41
28
42
# Minimum target platform versions.
@@ -33,11 +47,15 @@ if "macos_deployment_target" not in ARGUMENTS:
33
47
if "android_api_level" not in ARGUMENTS :
34
48
ARGUMENTS ["android_api_level" ] = "28"
35
49
50
+ # Recent godot-cpp versions disables exceptions by default, but libdatachannel requires them.
51
+ ARGUMENTS ["disable_exceptions" ] = "no"
52
+
36
53
if env ["godot_version" ] == "3" :
37
54
if "platform" in ARGUMENTS and ARGUMENTS ["platform" ] == "macos" :
38
55
ARGUMENTS ["platform" ] = "osx" # compatibility with old osx name
39
56
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 )
41
59
42
60
# Patch base env
43
61
replace_flags (
@@ -105,9 +123,18 @@ if env["godot_version"] == "3":
105
123
for flags in (env ["CCFLAGS" ], env ["LINKFLAGS" ], cpp_env ["CCFLAGS" ], cpp_env ["LINKFLAGS" ]):
106
124
replace_flags (flags , {"-m32" : None , "-m64" : None })
107
125
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 ()
109
129
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" })
111
138
112
139
# Should probably go to upstream godot-cpp.
113
140
# We let SCons build its default ENV as it includes OS-specific things which we don't
0 commit comments