@@ -338,6 +338,41 @@ 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
+ opts .Add (
368
+ PathVariable (
369
+ "install_data_dir" ,
370
+ "The directory to install misc files (relative from the prefix)" ,
371
+ "share/godot-cpp" ,
372
+ PathVariable .PathAccept ,
373
+ )
374
+ )
375
+
341
376
# Add platform options (custom tools can override platforms)
342
377
for pl in sorted (set (platforms + custom_platforms )):
343
378
tool = Tool (pl , toolpath = get_platform_tools_paths (env ))
@@ -526,6 +561,7 @@ def generate(env):
526
561
}
527
562
)
528
563
env .AddMethod (_godot_cpp , "GodotCPP" )
564
+ env .AddMethod (_installable , "InstallableGodotCPP" )
529
565
530
566
531
567
def _godot_cpp (env ):
@@ -571,3 +607,61 @@ def _godot_cpp(env):
571
607
572
608
env .AppendUnique (LIBS = [env .File ("bin/%s" % library_name )])
573
609
return library
610
+
611
+
612
+ def _installable (env , library ):
613
+ import itertools
614
+ import json
615
+
616
+ install_lib_dir = os .path .join (env ["install_prefix_dir" ], env ["install_lib_dir" ])
617
+ install_pkgconfig_dir = os .path .join (install_lib_dir , "pkgconfig" )
618
+ install_include_dir = os .path .join (env ["install_prefix_dir" ], env ["install_include_dir" ])
619
+ install_data_dir = os .path .join (env ["install_prefix_dir" ], env ["install_data_dir" ])
620
+
621
+ # Obtain the gdextension version
622
+ extension_dir = normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ), env )
623
+ api_filename = normalize_path (
624
+ env .get ("custom_api_file" , env .File (extension_dir + "/extension_api.json" ).abspath ),
625
+ env ,
626
+ )
627
+ with open (api_filename , "r" ) as api_json_file :
628
+ api_data = json .load (api_json_file )
629
+ version_major = api_data ["header" ]["version_major" ]
630
+ version_minor = api_data ["header" ]["version_minor" ]
631
+ version_patch = api_data ["header" ]["version_patch" ]
632
+ gd_version = f"{ version_major } .{ version_minor } .{ version_patch } "
633
+ api_data = None
634
+
635
+ # Configure and install the pkgconfig file
636
+ libname = str (library [0 ])
637
+ pkgconfig = env .Substfile (
638
+ target = "gen/godot-cpp.pc" ,
639
+ source = "cmake/godot-cpp.pc.in" ,
640
+ SUBST_DICT = {
641
+ "@PROJECT_NAME@" : "godot-cpp" ,
642
+ "@CMAKE_INSTALL_LIBDIR@" : install_lib_dir ,
643
+ "@CMAKE_INSTALL_INCLUDEDIR@" : install_include_dir ,
644
+ "@GODOT_API_VERSION@" : gd_version ,
645
+ "@GODOTCPP_OUTPUT_NAME@" : libname ,
646
+ },
647
+ )
648
+ env .Install (install_pkgconfig_dir , pkgconfig )
649
+
650
+ # Install the headers
651
+ headers_from = []
652
+ headers_to = []
653
+ for dir_from , _ , file_lst in itertools .chain (os .walk ("include/godot_cpp" ), os .walk ("gen/include/godot_cpp" )):
654
+ headers_from += [os .path .join (dir_from , filename ) for filename in file_lst ]
655
+ dir_to = os .path .join (install_include_dir , dir_from [dir_from .find ("/godot_cpp" ) + 1 :])
656
+ headers_to += [os .path .join (dir_to , filename ) for filename in file_lst ]
657
+ env .InstallAs (headers_to , headers_from )
658
+
659
+ # Install the gdextension files
660
+ interface_header = os .path .join (extension_dir , "gdextension_interface.h" )
661
+ env .Install (install_include_dir , interface_header )
662
+ env .Install (install_data_dir , api_filename )
663
+
664
+ # Install the static library
665
+ env .Install (install_lib_dir , library )
666
+
667
+ env .Alias ("install" , env ["install_prefix_dir" ])
0 commit comments