2023-08-05 22:42:21 +00:00
|
|
|
#!/usr/bin/env python
|
2023-08-17 14:25:50 +00:00
|
|
|
import os
|
2024-08-08 22:19:52 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from methods import print_error
|
2023-08-17 14:25:50 +00:00
|
|
|
|
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
if not (os.path.isdir("godot-cpp") and os.listdir("godot-cpp")):
|
|
|
|
print_error("""godot-cpp is not available within this folder, as Git submodules haven"t been initialized.
|
|
|
|
Run the following command to download godot-cpp:
|
|
|
|
|
|
|
|
git submodule update --init --recursive""")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
# ============================= General Lib Info =============================
|
|
|
|
|
2023-08-05 22:42:21 +00:00
|
|
|
libname = "EXTENSION-NAME"
|
2023-10-15 17:50:01 +00:00
|
|
|
projectdir = "demo"
|
2023-08-05 22:42:21 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
gdextension_tool = Tool("gdextension")
|
|
|
|
|
|
|
|
# ============================= Setup Options =============================
|
2023-08-17 14:25:50 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
# Load variables from custom.py, in case someone wants to store their own arguments.
|
|
|
|
# See https://scons.org/doc/production/HTML/scons-user.html#app-tools // search custom.py
|
2023-08-17 14:25:50 +00:00
|
|
|
customs = ["custom.py"]
|
|
|
|
customs = [os.path.abspath(path) for path in customs]
|
|
|
|
opts = Variables(customs, ARGUMENTS)
|
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
gdextension_tool.options(opts)
|
2023-08-17 14:25:50 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
# Remove our custom options to avoid passing to godot-cpp; godot-cpp has its own check for unknown options.
|
|
|
|
for opt in opts.options:
|
|
|
|
ARGUMENTS.pop(opt.key, None)
|
2023-08-17 14:25:50 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
# ============================= Setup godot-cpp =============================
|
2024-08-08 22:19:52 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
godot_cpp_env = SConscript("godot-cpp/SConstruct", {"customs": customs})
|
2024-08-08 22:19:52 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
gdextension_env = godot_cpp_env.Clone()
|
|
|
|
opts.Update(gdextension_env)
|
|
|
|
Help(opts.GenerateHelpText(gdextension_env))
|
2024-08-08 22:19:52 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
# ============================= Setup Targets =============================
|
2023-08-05 22:42:21 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
sources = []
|
|
|
|
targets = []
|
2023-08-05 22:42:21 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
gdextension_tool.generate(gdextension_env, godot_cpp_env, sources)
|
2024-08-16 18:39:39 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
file = "{}{}{}".format(libname, godot_cpp_env["suffix"], godot_cpp_env["SHLIBSUFFIX"])
|
2024-09-17 00:25:31 +00:00
|
|
|
filepath = ""
|
2023-10-15 17:50:01 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
if godot_cpp_env["platform"] == "macos" or godot_cpp_env["platform"] == "ios":
|
|
|
|
filepath = "{}.framework/".format(godot_cpp_env["platform"])
|
|
|
|
file = "{}.{}.{}".format(libname, godot_cpp_env["platform"], godot_cpp_env["target"])
|
2023-10-15 17:50:01 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
libraryfile = "bin/{}/{}{}".format(godot_cpp_env["platform"], filepath, file)
|
|
|
|
library = gdextension_env.SharedLibrary(
|
2023-10-15 17:50:01 +00:00
|
|
|
libraryfile,
|
|
|
|
source=sources,
|
|
|
|
)
|
2024-11-17 21:48:34 +00:00
|
|
|
targets.append(library)
|
2023-10-15 17:50:01 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
targets.append(gdextension_env.Install("{}/bin/{}/{}".format(projectdir, godot_cpp_env["platform"], filepath), library))
|
2023-08-05 22:42:21 +00:00
|
|
|
|
2024-11-17 21:48:34 +00:00
|
|
|
Default(targets)
|