Skip to content

Commit bb02a3e

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

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

SConstruct

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

51+
env.InstallableGodotCPP(library)
52+
5153
Return("env")

tools/godotcpp.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,42 @@ 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+
342+
# Scons lack a default install prefix, so use CMake's as a default for feature parity
343+
# https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html
344+
opts.Add(
345+
PathVariable(
346+
"install_prefix_dir",
347+
"The directory to install to",
348+
"C:/Program Files/godot-cpp" if default_platform == "windows" else "/usr/local",
349+
PathVariable.PathAccept,
350+
)
351+
)
352+
opts.Add(
353+
PathVariable(
354+
"install_lib_dir",
355+
"The directory to install the library (relative from the prefix)",
356+
"lib",
357+
PathVariable.PathAccept,
358+
)
359+
)
360+
opts.Add(
361+
PathVariable(
362+
"install_include_dir",
363+
"The directory to install the headers (relative from the prefix)",
364+
"include",
365+
PathVariable.PathAccept,
366+
)
367+
)
368+
opts.Add(
369+
PathVariable(
370+
"install_data_dir",
371+
"The directory to install misc files (relative from the prefix)",
372+
"share/godot-cpp",
373+
PathVariable.PathAccept,
374+
)
375+
)
376+
341377
# Add platform options (custom tools can override platforms)
342378
for pl in sorted(set(platforms + custom_platforms)):
343379
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
@@ -526,6 +562,7 @@ def generate(env):
526562
}
527563
)
528564
env.AddMethod(_godot_cpp, "GodotCPP")
565+
env.AddMethod(_installable, "InstallableGodotCPP")
529566

530567

531568
def _godot_cpp(env):
@@ -571,3 +608,61 @@ def _godot_cpp(env):
571608

572609
env.AppendUnique(LIBS=[env.File("bin/%s" % library_name)])
573610
return library
611+
612+
613+
def _installable(env, library):
614+
import itertools
615+
import json
616+
617+
install_lib_dir = os.path.join(env["install_prefix_dir"], env["install_lib_dir"])
618+
install_pkgconfig_dir = os.path.join(install_lib_dir, "pkgconfig")
619+
install_include_dir = os.path.join(env["install_prefix_dir"], env["install_include_dir"])
620+
install_data_dir = os.path.join(env["install_prefix_dir"], env["install_data_dir"])
621+
622+
# Obtain the gdextension version
623+
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
624+
api_filename = normalize_path(
625+
env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath),
626+
env,
627+
)
628+
with open(api_filename, "r") as api_json_file:
629+
api_data = json.load(api_json_file)
630+
version_major = api_data["header"]["version_major"]
631+
version_minor = api_data["header"]["version_minor"]
632+
version_patch = api_data["header"]["version_patch"]
633+
gd_version = f"{version_major}.{version_minor}.{version_patch}"
634+
api_data = None
635+
636+
# Configure and install the pkgconfig file
637+
libname = str(library[0])
638+
pkgconfig = env.Substfile(
639+
target="gen/godot-cpp.pc",
640+
source="cmake/godot-cpp.pc.in",
641+
SUBST_DICT={
642+
"@PROJECT_NAME@": "godot-cpp",
643+
"@CMAKE_INSTALL_LIBDIR@": install_lib_dir,
644+
"@CMAKE_INSTALL_INCLUDEDIR@": install_include_dir,
645+
"@GODOT_API_VERSION@": gd_version,
646+
"@GODOTCPP_OUTPUT_NAME@": libname,
647+
},
648+
)
649+
env.Install(install_pkgconfig_dir, pkgconfig)
650+
651+
# Install the headers
652+
headers_from = []
653+
headers_to = []
654+
for dir_from, _, file_lst in itertools.chain(os.walk("include/godot_cpp"), os.walk("gen/include/godot_cpp")):
655+
headers_from += [os.path.join(dir_from, filename) for filename in file_lst]
656+
dir_to = os.path.join(install_include_dir, dir_from[dir_from.find("/godot_cpp") + 1 :])
657+
headers_to += [os.path.join(dir_to, filename) for filename in file_lst]
658+
env.InstallAs(headers_to, headers_from)
659+
660+
# Install the gdextension files
661+
interface_header = os.path.join(extension_dir, "gdextension_interface.h")
662+
env.Install(install_include_dir, interface_header)
663+
env.Install(install_data_dir, api_filename)
664+
665+
# Install the static library
666+
env.Install(install_lib_dir, library)
667+
668+
env.Alias("install", env["install_prefix_dir"])

0 commit comments

Comments
 (0)