3
3
import os
4
4
import sys
5
5
import subprocess
6
+ from binding_generator import scons_generate_bindings , scons_emit_files
6
7
7
8
if sys .version_info < (3 ,):
8
9
@@ -112,13 +113,7 @@ opts.Add(
112
113
)
113
114
opts .Add (PathVariable ("custom_api_file" , "Path to a custom JSON API file" , None , PathVariable .PathIsFile ))
114
115
opts .Add (
115
- EnumVariable (
116
- "generate_bindings" ,
117
- "Generate GDNative API bindings" ,
118
- "auto" ,
119
- allowed_values = ["yes" , "no" , "auto" , "true" ],
120
- ignorecase = 2 ,
121
- )
116
+ BoolVariable ("generate_bindings" , "Force GDExtension API bindings generation. Auto-detected by default." , False )
122
117
)
123
118
opts .Add (EnumVariable ("android_arch" , "Target Android architecture" , "armv7" , ["armv7" , "arm64v8" , "x86" , "x86_64" ]))
124
119
opts .Add ("macos_deployment_target" , "macOS deployment target" , "default" )
@@ -442,43 +437,33 @@ elif env["platform"] == "javascript":
442
437
elif env ["target" ] == "release" :
443
438
env .Append (CCFLAGS = ["-O3" ])
444
439
445
- env .Append (
446
- CPPPATH = [
447
- "." ,
448
- env ["headers_dir" ],
449
- "#include" ,
450
- "#gen/include" ,
451
- ]
452
- )
453
-
454
- # Generate bindings?
440
+ # Generate bindings
441
+ env .Append (BUILDERS = {"GenerateBindings" : Builder (action = scons_generate_bindings , emitter = scons_emit_files )})
455
442
json_api_file = ""
456
443
457
444
if "custom_api_file" in env :
458
445
json_api_file = env ["custom_api_file" ]
459
446
else :
460
447
json_api_file = os .path .join (os .getcwd (), env ["headers_dir" ], "extension_api.json" )
461
448
462
- if env ["generate_bindings" ] == "auto" :
463
- # Check if generated files exist
464
- should_generate_bindings = not os .path .isfile (os .path .join (os .getcwd (), "gen" , "src" , "classes" , "object.cpp" ))
465
- else :
466
- should_generate_bindings = env ["generate_bindings" ] in ["yes" , "true" ]
449
+ bindings = env .GenerateBindings (
450
+ env .Dir ("." ), [json_api_file , os .path .join (env ["headers_dir" ], "godot" , "gdnative_interface.h" )]
451
+ )
467
452
468
- if should_generate_bindings :
469
- # Actually create the bindings here
470
- import binding_generator
453
+ # Forces bindings regeneration.
454
+ if env [ "generate_bindings" ]:
455
+ AlwaysBuild ( bindings )
471
456
472
- binding_generator .generate_bindings (json_api_file , env ["generate_template_get_node" ])
457
+ # Includes
458
+ env .Append (CPPPATH = [[env .Dir (d ) for d in [env ["headers_dir" ], "include" , os .path .join ("gen" , "include" )]]])
473
459
474
460
# Sources to compile
475
461
sources = []
476
462
add_sources (sources , "src" , "cpp" )
477
463
add_sources (sources , "src/classes" , "cpp" )
478
464
add_sources (sources , "src/core" , "cpp" )
479
465
add_sources (sources , "src/variant" , "cpp" )
480
- add_sources (sources , "gen/src/variant" , "cpp" )
481
- add_sources (sources , "gen/src/classes" , "cpp" )
466
+ sources .extend ([f for f in bindings if str (f ).endswith (".cpp" )])
482
467
483
468
env ["arch_suffix" ] = env ["bits" ]
484
469
if env ["platform" ] == "android" :
@@ -500,7 +485,6 @@ if env["build_library"]:
500
485
library = env .StaticLibrary (target = env .File ("bin/%s" % library_name ), source = sources )
501
486
Default (library )
502
487
503
- env .Append (CPPPATH = [env .Dir (f ) for f in ["gen/include" , "include" , "godot-headers" ]])
504
488
env .Append (LIBPATH = [env .Dir ("bin" )])
505
489
env .Append (LIBS = library_name )
506
490
Return ("env" )
0 commit comments