12
12
from binding_generator import scons_generate_bindings , scons_emit_files
13
13
14
14
15
- def add_sources (sources , dir , extension ):
16
- for f in os .listdir (dir ):
17
- if f .endswith ("." + extension ):
18
- sources .append (dir + "/" + f )
19
-
20
-
21
15
def get_cmdline_bool (option , default ):
22
16
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
23
17
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -30,6 +24,10 @@ def get_cmdline_bool(option, default):
30
24
31
25
32
26
def normalize_path (val , env ):
27
+ """Normalize a path that was provided by the user on the command line
28
+ and is thus either an absolute path or relative to the top level directory (#)
29
+ where the command was run
30
+ """
33
31
return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
34
32
35
33
@@ -50,9 +48,10 @@ def validate_parent_dir(key, val, env):
50
48
51
49
def get_platform_tools_paths (env ):
52
50
path = env .get ("custom_tools" , None )
51
+ tools_path = env .Dir ("tools" ).srcnode ().abspath
53
52
if path is None :
54
- return ["tools" ]
55
- return [normalize_path (path , env ), "tools" ]
53
+ return [tools_path ]
54
+ return [normalize_path (path , env ), tools_path ]
56
55
57
56
58
57
def get_custom_platforms (env ):
@@ -458,8 +457,22 @@ def generate(env):
458
457
459
458
460
459
def _godot_cpp (env ):
461
- extension_dir = normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ), env )
462
- api_file = normalize_path (env .get ("custom_api_file" , env .File (extension_dir + "/extension_api.json" ).abspath ), env )
460
+ extension_dir = env .get ("gdextension_dir" , None )
461
+ # A user provided extension_dir is relative to where they are running from (#)
462
+ # But our gdextension directory is here in the source tree
463
+ if extension_dir is not None :
464
+ extension_dir = normalize_path (extension_dir , env )
465
+ else :
466
+ extension_dir = env .Dir ("gdextension" ).srcnode ().abspath
467
+
468
+ api_file = env .get ("custom_api_file" , None )
469
+ # A user provided api_file is relative to where they are running from (#)
470
+ # But a default api_file is relative to extension_dir
471
+ if api_file is not None :
472
+ api_file = normalize_path (api_file , env )
473
+ else :
474
+ api_file = os .path .join (extension_dir , "extension_api.json" )
475
+
463
476
bindings = env .GodotCPPBindings (
464
477
env .Dir ("." ),
465
478
[
@@ -474,15 +487,12 @@ def _godot_cpp(env):
474
487
env .NoCache (bindings )
475
488
476
489
# Sources to compile
477
- sources = []
478
- add_sources (sources , "src" , "cpp" )
479
- add_sources (sources , "src/classes" , "cpp" )
480
- add_sources (sources , "src/core" , "cpp" )
481
- add_sources (sources , "src/variant" , "cpp" )
490
+ sources = env .Glob ("src/*.cpp" )
491
+ sources += env .Glob ("src/*/*.cpp" )
482
492
sources .extend ([f for f in bindings if str (f ).endswith (".cpp" )])
483
493
484
494
# Includes
485
- env .AppendUnique (CPPPATH = [env .Dir (d ) for d in [ extension_dir , "include" , "gen/include" ] ])
495
+ env .AppendUnique (CPPPATH = [env .Dir (extension_dir ), env . Dir ( "include" ). srcnode (), env . Dir ( "gen/include" ) ])
486
496
487
497
library = None
488
498
library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments