godot-cpp-template/SConstruct

107 lines
3.4 KiB
Python

#!/usr/bin/env python
import os
import sys
from methods import print_error
def normalize_path(val, env):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
def validate_parent_dir(key, val, env):
if not os.path.isdir(normalize_path(os.path.dirname(val), env)):
raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))
libname = "EXTENSION-NAME"
projectdir = "demo"
localEnv = Environment(tools=["default"], PLATFORM="")
customs = ["custom.py"]
customs = [os.path.abspath(path) for path in customs]
opts = Variables(customs, ARGUMENTS)
opts.Add(
BoolVariable(
key="compiledb",
help="Generate compilation DB (`compile_commands.json`) for external tools",
default=localEnv.get("compiledb", False),
)
)
opts.Add(
PathVariable(
key="compiledb_file",
help="Path to a custom `compile_commands.json` file",
default=localEnv.get("compiledb_file", "compile_commands.json"),
validator=validate_parent_dir,
)
)
opts.Update(localEnv)
Help(opts.GenerateHelpText(localEnv))
env = localEnv.Clone()
env["compiledb"] = False
env.Tool("compilation_db")
compilation_db = env.CompilationDatabase(
normalize_path(localEnv["compiledb_file"], localEnv)
)
env.Alias("compiledb", compilation_db)
submodule_initialized = False
dir_name = 'godot-cpp'
if os.path.isdir(dir_name):
if os.listdir(dir_name):
submodule_initialized = True
if not submodule_initialized:
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)
env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
env.Append(CPPPATH=["src/"])
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.")
lib_filename = "{}{}{}{}".format(env.subst("$SHLIBPREFIX"), libname, env["suffix"], env.subst("$SHLIBSUFFIX"))
lib_filepath = ""
if env["platform"] == "macos" or env["platform"] == "ios":
# By default, the above code generates .dylib files on macOS and iOS.
# The App Store rejects entries containing .dylib files, requiring a .framework structure instead.
# Details about the .framework structure are described Framework Programming Guide:
# https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html#//apple_ref/doc/uid/20002253-BAJEJJAB
framework_name = "{}{}".format(libname, env["suffix"])
lib_filename = framework_name
lib_filepath = "{}.framework/".format(framework_name)
# Prevents the binary from getting a prefix / suffix automatically
env["SHLIBPREFIX"] = ""
env["SHLIBSUFFIX"] = ""
libraryfile = "bin/{}/{}{}".format(env["platform"], lib_filepath, lib_filename)
library = env.SharedLibrary(
libraryfile,
source=sources,
)
copy = env.Install("{}/bin/{}/{}".format(projectdir, env["platform"], lib_filepath), library),
default_args = [library, copy]
if localEnv.get("compiledb", False):
default_args += [compilation_db]
Default(*default_args)