@@ -338,6 +338,33 @@ def options(opts, env):
338
338
opts .Add (BoolVariable ("dev_build" , "Developer build with dev-only debugging code (DEV_ENABLED)" , False ))
339
339
opts .Add (BoolVariable ("verbose" , "Enable verbose output for the compilation" , False ))
340
340
341
+ # Scons lack a default install prefix, so use CMake's as a default for feature parity
342
+ # https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html
343
+ opts .Add (
344
+ PathVariable (
345
+ "install_prefix_dir" ,
346
+ "The directory to install to" ,
347
+ "C:/Program Files/godot-cpp" if default_platform == "windows" else "/usr/local" ,
348
+ PathVariable .PathAccept ,
349
+ )
350
+ )
351
+ opts .Add (
352
+ PathVariable (
353
+ "install_lib_dir" ,
354
+ "The directory to install the library (relative from the prefix)" ,
355
+ "lib" ,
356
+ PathVariable .PathAccept ,
357
+ )
358
+ )
359
+ opts .Add (
360
+ PathVariable (
361
+ "install_include_dir" ,
362
+ "The directory to install the headers (relative from the prefix)" ,
363
+ "include" ,
364
+ PathVariable .PathAccept ,
365
+ )
366
+ )
367
+
341
368
# Add platform options (custom tools can override platforms)
342
369
for pl in sorted (set (platforms + custom_platforms )):
343
370
tool = Tool (pl , toolpath = get_platform_tools_paths (env ))
@@ -526,6 +553,7 @@ def generate(env):
526
553
}
527
554
)
528
555
env .AddMethod (_godot_cpp , "GodotCPP" )
556
+ env .AddMethod (_installable , "InstallableGodotCPP" )
529
557
530
558
531
559
def _godot_cpp (env ):
@@ -571,3 +599,58 @@ def _godot_cpp(env):
571
599
572
600
env .AppendUnique (LIBS = [env .File ("bin/%s" % library_name )])
573
601
return library
602
+
603
+
604
+ def _installable (env , library ):
605
+ import itertools
606
+ import json
607
+
608
+ install_prefix_dir = env ["install_prefix_dir" ]
609
+ full_install_lib_dir = os .path .join (install_prefix_dir , env ["install_lib_dir" ])
610
+ full_install_include_dir = os .path .join (install_prefix_dir , env ["install_include_dir" ])
611
+
612
+ # Obtain the gdextension version
613
+ extension_dir = normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ), env )
614
+ api_filename = normalize_path (
615
+ env .get ("custom_api_file" , env .File (extension_dir + "/extension_api.json" ).abspath ),
616
+ env ,
617
+ )
618
+ with open (api_filename , "r" ) as api_json_file :
619
+ api_data = json .load (api_json_file )
620
+ version_major = api_data ["header" ]["version_major" ]
621
+ version_minor = api_data ["header" ]["version_minor" ]
622
+ version_patch = api_data ["header" ]["version_patch" ]
623
+ gd_version = f"{ version_major } .{ version_minor } .{ version_patch } "
624
+
625
+ # Configure and install the pkgconfig file
626
+ libname = str (library [0 ])
627
+ pkgconfig = env .Substfile (
628
+ target = "gen/godot-cpp.pc" ,
629
+ source = "cmake/godot-cpp.pc.in" ,
630
+ SUBST_DICT = {
631
+ "@CMAKE_INSTALL_PREFIX@" : install_prefix_dir ,
632
+ "@CMAKE_INSTALL_FULL_INCLUDEDIR@" : full_install_include_dir ,
633
+ "@CMAKE_INSTALL_FULL_LIBDIR@" : full_install_lib_dir ,
634
+ "@GODOT_API_VERSION@" : gd_version ,
635
+ "@GODOTCPP_OUTPUT_NAME@" : libname ,
636
+ },
637
+ )
638
+ full_install_pkgconfig_dir = os .path .join (full_install_lib_dir , "pkgconfig" )
639
+ env .Install (full_install_pkgconfig_dir , pkgconfig )
640
+
641
+ # Install the headers
642
+ headers_from = []
643
+ headers_to = []
644
+ for dir_from , _ , file_lst in itertools .chain (os .walk ("include/godot_cpp" ), os .walk ("gen/include/godot_cpp" )):
645
+ dir_to = os .path .join (full_install_include_dir , dir_from [dir_from .find ("/godot_cpp" ) + 1 :])
646
+ headers_from += [os .path .join (dir_from , filename ) for filename in file_lst ]
647
+ headers_to += [os .path .join (dir_to , filename ) for filename in file_lst ]
648
+ env .InstallAs (headers_to , headers_from )
649
+ # Install the gdextension files
650
+ interface_header = os .path .join (extension_dir , "gdextension_interface.h" )
651
+ env .Install (full_install_include_dir , interface_header )
652
+
653
+ # Install the static library
654
+ env .Install (full_install_lib_dir , library )
655
+
656
+ env .Alias ("install" , env ["install_prefix_dir" ])
0 commit comments