Skip to content

[SCons] Add GDExtension method to scons. #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ def add_sources(sources, dir, extension):
sources.append(dir + "/" + f)


def make_gdextension(env, name, sources, library_dir="lib", entry_symbol="", output_dir=""):
target_dir = output_dir if output_dir else name
init = entry_symbol if entry_symbol else f"{name}_library_init"
autodetect_prefix = "{}/lib{}".format(library_dir, name)
lib = env.SharedLibrary(
target_dir + "/" + "{}{}{}".format(autodetect_prefix, env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)
ext_text = """[configuration]
entry_symbol = "{}"

[libraries]
autodetect_prefix = "{}"
""".format(
init, autodetect_prefix
)
config = env.Textfile("{}/{}.gdextension".format(target_dir, name), ext_text)
env.AlwaysBuild(config)
env.NoCache(config)
return [env.Dir(target_dir), lib, config]


# Try to detect the host platform automatically.
# This is used if no `platform` argument is passed
if sys.platform.startswith("linux"):
Expand Down Expand Up @@ -229,4 +251,5 @@ if env["build_library"]:

env.Append(LIBPATH=[env.Dir("bin")])
env.Append(LIBS=library_name)
env.AddMethod(make_gdextension, "GDExtension")
Return("env")
3 changes: 3 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
build
bin

# Generated extension directory
demo/gdexample

# Godot 4+ specific ignores
.godot/

Expand Down
14 changes: 1 addition & 13 deletions test/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,5 @@ env = SConscript("../SConstruct")
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

if env["platform"] == "macos":
library = env.SharedLibrary(
"demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
env["platform"], env["target"], env["platform"], env["target"]
),
source=sources,
)
else:
library = env.SharedLibrary(
"demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)

library = env.GDExtension("gdexample", sources, output_dir="demo/gdexample")
Default(library)
18 changes: 0 additions & 18 deletions test/demo/example.gdextension

This file was deleted.

2 changes: 1 addition & 1 deletion test/src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void uninitialize_example_module(ModuleInitializationLevel p_level) {

extern "C" {
// Initialization.
GDNativeBool GDN_EXPORT example_library_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) {
GDNativeBool GDN_EXPORT gdexample_library_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);

init_obj.register_initializer(initialize_example_module);
Expand Down