33import os
44import sys
55import subprocess
6+ from binding_generator import scons_generate_bindings , scons_emit_files
67
78if sys .version_info < (3 ,):
89
@@ -112,13 +113,7 @@ opts.Add(
112113)
113114opts .Add (PathVariable ("custom_api_file" , "Path to a custom JSON API file" , None , PathVariable .PathIsFile ))
114115opts .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 )
122117)
123118opts .Add (EnumVariable ("android_arch" , "Target Android architecture" , "armv7" , ["armv7" , "arm64v8" , "x86" , "x86_64" ]))
124119opts .Add ("macos_deployment_target" , "macOS deployment target" , "default" )
@@ -442,43 +437,33 @@ elif env["platform"] == "javascript":
442437 elif env ["target" ] == "release" :
443438 env .Append (CCFLAGS = ["-O3" ])
444439
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 )})
455442json_api_file = ""
456443
457444if "custom_api_file" in env :
458445 json_api_file = env ["custom_api_file" ]
459446else :
460447 json_api_file = os .path .join (os .getcwd (), env ["headers_dir" ], "extension_api.json" )
461448
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+ )
467452
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 )
471456
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" )]]])
473459
474460# Sources to compile
475461sources = []
476462add_sources (sources , "src" , "cpp" )
477463add_sources (sources , "src/classes" , "cpp" )
478464add_sources (sources , "src/core" , "cpp" )
479465add_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" )])
482467
483468env ["arch_suffix" ] = env ["bits" ]
484469if env ["platform" ] == "android" :
@@ -500,7 +485,6 @@ if env["build_library"]:
500485 library = env .StaticLibrary (target = env .File ("bin/%s" % library_name ), source = sources )
501486 Default (library )
502487
503- env .Append (CPPPATH = [env .Dir (f ) for f in ["gen/include" , "include" , "godot-headers" ]])
504488env .Append (LIBPATH = [env .Dir ("bin" )])
505489env .Append (LIBS = library_name )
506490Return ("env" )
0 commit comments