OverviewFilesCommitsIssuesDocsReleasesPeers

blender-bridge / SConstruct

68 lines · text ref:
#!/usr/bin/env python
import os
import sys

from methods import print_error

libname = "blender_bridge"

localEnv = Environment(tools=["default"], PLATFORM="")

customs = ["custom.py"]
customs = [os.path.abspath(path) for path in customs]

opts = Variables(customs, ARGUMENTS)
opts.Update(localEnv)

Help(opts.GenerateHelpText(localEnv))

env = localEnv.Clone()

if not (os.path.isdir("godot-cpp") and os.listdir("godot-cpp")):
    print_error("""godot-cpp is not available within this folder.
Either clone it as a submodule or symlink it:

    git submodule update --init --recursive
    # or
    ln -s /path/to/godot-cpp godot-cpp""")
    sys.exit(1)

env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})

# Allow overriding CC/CXX via environment variables (e.g. for Zig cross-compilation)
if os.environ.get("CC"):
    env["CC"] = os.environ["CC"]
if os.environ.get("CXX"):
    env["CXX"] = os.environ["CXX"]
# Zig doesn't recognize .os extension — use .o for shared object files
if "zig" in os.environ.get("CC", ""):
    env["SHOBJSUFFIX"] = ".o"

env.Append(CPPPATH=["src/"])

# POSIX shared memory (shm_open) requires -lrt on Linux
if env["platform"] == "linux":
    env.Append(LIBS=["rt"])

sources = Glob("src/*.cpp")

if env["target"] in ["editor", "template_debug"]:
    try:
        doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
        sources.append(doc_data)
    except AttributeError:
        print("Not including class reference as we're targeting a pre-4.3 baseline.")

suffix = env["suffix"].replace(".dev", "").replace(".universal", "")

lib_filename = "{}{}{}{}".format(
    env.subst("$SHLIBPREFIX"), libname, suffix, env.subst("$SHLIBSUFFIX")
)

library = env.SharedLibrary(
    "bin/{}/{}".format(env["platform"], lib_filename),
    source=sources,
)

Default(library)