Skip to content

Commit c7f4f49

Browse files
committed
Make godot-cpp installable via ScCons
This aims to have feature parity with the installation via cmake
1 parent c09f7a7 commit c7f4f49

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

SConstruct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ if scons_cache_path is not None:
4848
cpp_tool.generate(env)
4949
library = env.GodotCPP()
5050

51+
if library:
52+
env.InstallableGodotCPP(library)
53+
5154
Return("env")

tools/godotcpp.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,41 @@ def options(opts, env):
338338
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
339339
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
340340

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+
341376
# Add platform options (custom tools can override platforms)
342377
for pl in sorted(set(platforms + custom_platforms)):
343378
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
@@ -526,6 +561,7 @@ def generate(env):
526561
}
527562
)
528563
env.AddMethod(_godot_cpp, "GodotCPP")
564+
env.AddMethod(_installable, "InstallableGodotCPP")
529565

530566

531567
def _godot_cpp(env):
@@ -571,3 +607,61 @@ def _godot_cpp(env):
571607

572608
env.AppendUnique(LIBS=[env.File("bin/%s" % library_name)])
573609
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

Comments
 (0)