2024-06-24 17:20:55 +00:00
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import sys
|
2023-07-22 15:59:11 +00:00
|
|
|
|
2024-01-18 20:22:16 +00:00
|
|
|
from SCons.Action import Action
|
2023-07-22 15:59:11 +00:00
|
|
|
from SCons.Builder import Builder
|
2023-09-09 08:55:53 +00:00
|
|
|
from SCons.Errors import UserError
|
2024-02-14 14:32:27 +00:00
|
|
|
from SCons.Script import ARGUMENTS
|
2024-06-24 17:20:55 +00:00
|
|
|
from SCons.Tool import Tool
|
|
|
|
from SCons.Variables import BoolVariable, EnumVariable, PathVariable
|
|
|
|
from SCons.Variables.BoolVariable import _text2bool
|
2024-02-14 14:32:27 +00:00
|
|
|
|
2024-06-24 17:20:55 +00:00
|
|
|
from binding_generator import scons_emit_files, scons_generate_bindings
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def add_sources(sources, dir, extension):
|
|
|
|
for f in os.listdir(dir):
|
|
|
|
if f.endswith("." + extension):
|
|
|
|
sources.append(dir + "/" + f)
|
|
|
|
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
def get_cmdline_bool(option, default):
|
|
|
|
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
|
|
|
|
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
|
|
|
|
"""
|
|
|
|
cmdline_val = ARGUMENTS.get(option)
|
|
|
|
if cmdline_val is not None:
|
|
|
|
return _text2bool(cmdline_val)
|
|
|
|
else:
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
def normalize_path(val, env):
|
|
|
|
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
|
|
|
|
|
|
|
|
|
|
|
|
def validate_file(key, val, env):
|
|
|
|
if not os.path.isfile(normalize_path(val, env)):
|
|
|
|
raise UserError("'%s' is not a file: %s" % (key, val))
|
|
|
|
|
|
|
|
|
|
|
|
def validate_dir(key, val, env):
|
|
|
|
if not os.path.isdir(normalize_path(val, env)):
|
|
|
|
raise UserError("'%s' is not a directory: %s" % (key, 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)))
|
|
|
|
|
|
|
|
|
2024-01-30 08:32:27 +00:00
|
|
|
def get_platform_tools_paths(env):
|
|
|
|
path = env.get("custom_tools", None)
|
|
|
|
if path is None:
|
|
|
|
return ["tools"]
|
|
|
|
return [normalize_path(path, env), "tools"]
|
|
|
|
|
|
|
|
|
|
|
|
def get_custom_platforms(env):
|
|
|
|
path = env.get("custom_tools", None)
|
|
|
|
if path is None:
|
|
|
|
return []
|
|
|
|
platforms = []
|
|
|
|
for x in os.listdir(normalize_path(path, env)):
|
|
|
|
if not x.endswith(".py"):
|
|
|
|
continue
|
|
|
|
platforms.append(x.removesuffix(".py"))
|
|
|
|
return platforms
|
|
|
|
|
|
|
|
|
2024-01-18 20:22:16 +00:00
|
|
|
def no_verbose(env):
|
|
|
|
colors = {}
|
|
|
|
|
|
|
|
# Colors are disabled in non-TTY environments such as pipes. This means
|
|
|
|
# that if output is redirected to a file, it will not contain color codes
|
|
|
|
if sys.stdout.isatty():
|
|
|
|
colors["blue"] = "\033[0;94m"
|
|
|
|
colors["bold_blue"] = "\033[1;94m"
|
|
|
|
colors["reset"] = "\033[0m"
|
|
|
|
else:
|
|
|
|
colors["blue"] = ""
|
|
|
|
colors["bold_blue"] = ""
|
|
|
|
colors["reset"] = ""
|
|
|
|
|
|
|
|
# There is a space before "..." to ensure that source file names can be
|
|
|
|
# Ctrl + clicked in the VS Code terminal.
|
|
|
|
compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
java_compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
compile_shared_source_message = "{}Compiling shared {}$SOURCE{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
link_program_message = "{}Linking Program {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
link_library_message = "{}Linking Static Library {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
ranlib_library_message = "{}Ranlib Library {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
link_shared_library_message = "{}Linking Shared Library {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
java_library_message = "{}Creating Java Archive {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
compiled_resource_message = "{}Creating Compiled Resource {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
generated_file_message = "{}Generating {}$TARGET{} ...{}".format(
|
|
|
|
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
|
|
|
)
|
|
|
|
|
|
|
|
env.Append(CXXCOMSTR=[compile_source_message])
|
|
|
|
env.Append(CCCOMSTR=[compile_source_message])
|
|
|
|
env.Append(SHCCCOMSTR=[compile_shared_source_message])
|
|
|
|
env.Append(SHCXXCOMSTR=[compile_shared_source_message])
|
|
|
|
env.Append(ARCOMSTR=[link_library_message])
|
|
|
|
env.Append(RANLIBCOMSTR=[ranlib_library_message])
|
|
|
|
env.Append(SHLINKCOMSTR=[link_shared_library_message])
|
|
|
|
env.Append(LINKCOMSTR=[link_program_message])
|
|
|
|
env.Append(JARCOMSTR=[java_library_message])
|
|
|
|
env.Append(JAVACCOMSTR=[java_compile_source_message])
|
|
|
|
env.Append(RCCOMSTR=[compiled_resource_message])
|
|
|
|
env.Append(GENCOMSTR=[generated_file_message])
|
|
|
|
|
|
|
|
|
2024-01-30 08:32:27 +00:00
|
|
|
platforms = ["linux", "macos", "windows", "android", "ios", "web"]
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
# CPU architecture options.
|
|
|
|
architecture_array = [
|
|
|
|
"",
|
|
|
|
"universal",
|
|
|
|
"x86_32",
|
|
|
|
"x86_64",
|
|
|
|
"arm32",
|
|
|
|
"arm64",
|
|
|
|
"rv64",
|
|
|
|
"ppc32",
|
|
|
|
"ppc64",
|
|
|
|
"wasm32",
|
|
|
|
]
|
|
|
|
architecture_aliases = {
|
|
|
|
"x64": "x86_64",
|
|
|
|
"amd64": "x86_64",
|
|
|
|
"armv7": "arm32",
|
|
|
|
"armv8": "arm64",
|
|
|
|
"arm64v8": "arm64",
|
|
|
|
"aarch64": "arm64",
|
|
|
|
"rv": "rv64",
|
|
|
|
"riscv": "rv64",
|
|
|
|
"riscv64": "rv64",
|
|
|
|
"ppcle": "ppc32",
|
|
|
|
"ppc": "ppc32",
|
|
|
|
"ppc64le": "ppc64",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def options(opts, env):
|
|
|
|
# Try to detect the host platform automatically.
|
|
|
|
# This is used if no `platform` argument is passed
|
|
|
|
if sys.platform.startswith("linux"):
|
|
|
|
default_platform = "linux"
|
|
|
|
elif sys.platform == "darwin":
|
|
|
|
default_platform = "macos"
|
|
|
|
elif sys.platform == "win32" or sys.platform == "msys":
|
|
|
|
default_platform = "windows"
|
|
|
|
elif ARGUMENTS.get("platform", ""):
|
|
|
|
default_platform = ARGUMENTS.get("platform")
|
|
|
|
else:
|
|
|
|
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
|
|
|
|
|
2024-01-30 08:32:27 +00:00
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
key="custom_tools",
|
|
|
|
help="Path to directory containing custom tools",
|
|
|
|
default=env.get("custom_tools", None),
|
|
|
|
validator=validate_dir,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
opts.Update(env)
|
|
|
|
|
|
|
|
custom_platforms = get_custom_platforms(env)
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
key="platform",
|
|
|
|
help="Target platform",
|
|
|
|
default=env.get("platform", default_platform),
|
2024-01-30 08:32:27 +00:00
|
|
|
allowed_values=platforms + custom_platforms,
|
2023-07-22 15:59:11 +00:00
|
|
|
ignorecase=2,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Editor and template_debug are compatible (i.e. you can use the same binary for Godot editor builds and Godot debug templates).
|
|
|
|
# Godot release templates are only compatible with "template_release" builds.
|
|
|
|
# For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds.
|
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
key="target",
|
|
|
|
help="Compilation target",
|
|
|
|
default=env.get("target", "template_debug"),
|
|
|
|
allowed_values=("editor", "template_release", "template_debug"),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
key="gdextension_dir",
|
|
|
|
help="Path to a custom directory containing GDExtension interface header and API JSON file",
|
|
|
|
default=env.get("gdextension_dir", None),
|
|
|
|
validator=validate_dir,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
key="custom_api_file",
|
|
|
|
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
|
|
|
|
default=env.get("custom_api_file", None),
|
|
|
|
validator=validate_file,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
key="generate_bindings",
|
|
|
|
help="Force GDExtension API bindings generation. Auto-detected by default.",
|
|
|
|
default=env.get("generate_bindings", False),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
key="generate_template_get_node",
|
|
|
|
help="Generate a template version of the Node class's get_node.",
|
|
|
|
default=env.get("generate_template_get_node", True),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
key="build_library",
|
|
|
|
help="Build the godot-cpp library.",
|
|
|
|
default=env.get("build_library", True),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
key="precision",
|
|
|
|
help="Set the floating-point precision level",
|
|
|
|
default=env.get("precision", "single"),
|
|
|
|
allowed_values=("single", "double"),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
key="arch",
|
|
|
|
help="CPU architecture",
|
|
|
|
default=env.get("arch", ""),
|
|
|
|
allowed_values=architecture_array,
|
|
|
|
map=architecture_aliases,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-04-30 17:06:51 +00:00
|
|
|
opts.Add(BoolVariable(key="threads", help="Enable threading support", default=env.get("threads", True)))
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
# compiledb
|
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
key="compiledb",
|
|
|
|
help="Generate compilation DB (`compile_commands.json`) for external tools",
|
|
|
|
default=env.get("compiledb", False),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
key="compiledb_file",
|
|
|
|
help="Path to a custom `compile_commands.json` file",
|
|
|
|
default=env.get("compiledb_file", "compile_commands.json"),
|
|
|
|
validator=validate_parent_dir,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-07-07 19:49:56 +00:00
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
"build_profile",
|
|
|
|
"Path to a file containing a feature build profile",
|
|
|
|
default=env.get("build_profile", None),
|
|
|
|
validator=validate_file,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-08-04 16:02:57 +00:00
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
key="use_hot_reload",
|
|
|
|
help="Enable the extra accounting required to support hot reload.",
|
2023-11-06 16:43:24 +00:00
|
|
|
default=env.get("use_hot_reload", None),
|
2023-08-04 16:02:57 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-08-16 09:47:19 +00:00
|
|
|
opts.Add(
|
|
|
|
BoolVariable(
|
|
|
|
"disable_exceptions", "Force disabling exception handling code", default=env.get("disable_exceptions", True)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-11-20 09:35:41 +00:00
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
key="symbols_visibility",
|
|
|
|
help="Symbols visibility on GNU platforms. Use 'auto' to apply the default value.",
|
|
|
|
default=env.get("symbols_visibility", "hidden"),
|
|
|
|
allowed_values=["auto", "visible", "hidden"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
"optimize",
|
|
|
|
"The desired optimization flags",
|
|
|
|
"speed_trace",
|
|
|
|
("none", "custom", "debug", "speed", "speed_trace", "size"),
|
|
|
|
)
|
|
|
|
)
|
2024-09-21 10:52:50 +00:00
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
"lto",
|
|
|
|
"Link-time optimization",
|
|
|
|
"none",
|
|
|
|
("none", "auto", "thin", "full"),
|
|
|
|
)
|
|
|
|
)
|
2024-02-14 14:32:27 +00:00
|
|
|
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True))
|
|
|
|
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
|
2024-01-18 20:22:16 +00:00
|
|
|
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
|
2024-02-14 14:32:27 +00:00
|
|
|
|
2024-11-13 22:02:15 +00:00
|
|
|
# Scons lack a default install prefix, so use CMake's as a default for feature parity
|
|
|
|
# https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
"install_prefix_dir",
|
|
|
|
"The directory to install to",
|
|
|
|
"C:/Program Files/godot-cpp" if default_platform == "windows" else "/usr/local",
|
|
|
|
PathVariable.PathAccept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
"install_lib_dir",
|
|
|
|
"The directory to install the library (relative from the prefix)",
|
|
|
|
"lib",
|
|
|
|
PathVariable.PathAccept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(
|
|
|
|
PathVariable(
|
|
|
|
"install_include_dir",
|
|
|
|
"The directory to install the headers (relative from the prefix)",
|
|
|
|
"include",
|
|
|
|
PathVariable.PathAccept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-01-30 08:32:27 +00:00
|
|
|
# Add platform options (custom tools can override platforms)
|
|
|
|
for pl in sorted(set(platforms + custom_platforms)):
|
|
|
|
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
|
2023-07-22 15:59:11 +00:00
|
|
|
if hasattr(tool, "options"):
|
|
|
|
tool.options(opts)
|
|
|
|
|
|
|
|
|
2024-01-25 14:54:58 +00:00
|
|
|
def make_doc_source(target, source, env):
|
|
|
|
import zlib
|
|
|
|
|
|
|
|
dst = str(target[0])
|
|
|
|
g = open(dst, "w", encoding="utf-8")
|
|
|
|
buf = ""
|
|
|
|
docbegin = ""
|
|
|
|
docend = ""
|
|
|
|
for src in source:
|
|
|
|
src_path = str(src)
|
|
|
|
if not src_path.endswith(".xml"):
|
|
|
|
continue
|
|
|
|
with open(src_path, "r", encoding="utf-8") as f:
|
|
|
|
content = f.read()
|
|
|
|
buf += content
|
|
|
|
|
|
|
|
buf = (docbegin + buf + docend).encode("utf-8")
|
|
|
|
decomp_size = len(buf)
|
|
|
|
|
|
|
|
# Use maximum zlib compression level to further reduce file size
|
|
|
|
# (at the cost of initial build times).
|
|
|
|
buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION)
|
|
|
|
|
|
|
|
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
|
|
|
g.write("\n")
|
|
|
|
g.write("#include <godot_cpp/godot.hpp>\n")
|
|
|
|
g.write("\n")
|
|
|
|
|
|
|
|
g.write('static const char *_doc_data_hash = "' + str(hash(buf)) + '";\n')
|
|
|
|
g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n")
|
|
|
|
g.write("static const int _doc_data_compressed_size = " + str(len(buf)) + ";\n")
|
|
|
|
g.write("static const unsigned char _doc_data_compressed[] = {\n")
|
|
|
|
for i in range(len(buf)):
|
|
|
|
g.write("\t" + str(buf[i]) + ",\n")
|
|
|
|
g.write("};\n")
|
|
|
|
g.write("\n")
|
|
|
|
|
|
|
|
g.write(
|
|
|
|
"static godot::internal::DocDataRegistration _doc_data_registration(_doc_data_hash, _doc_data_uncompressed_size, _doc_data_compressed_size, _doc_data_compressed);\n"
|
|
|
|
)
|
|
|
|
g.write("\n")
|
|
|
|
|
|
|
|
g.close()
|
|
|
|
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
def generate(env):
|
|
|
|
# Default num_jobs to local cpu count if not user specified.
|
|
|
|
# SCons has a peculiarity where user-specified options won't be overridden
|
|
|
|
# by SetOption, so we can rely on this to know if we should use our default.
|
|
|
|
initial_num_jobs = env.GetOption("num_jobs")
|
|
|
|
altered_num_jobs = initial_num_jobs + 1
|
|
|
|
env.SetOption("num_jobs", altered_num_jobs)
|
|
|
|
if env.GetOption("num_jobs") == altered_num_jobs:
|
|
|
|
cpu_count = os.cpu_count()
|
|
|
|
if cpu_count is None:
|
|
|
|
print("Couldn't auto-detect CPU count to configure build parallelism. Specify it with the -j argument.")
|
|
|
|
else:
|
|
|
|
safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1
|
|
|
|
print(
|
|
|
|
"Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the -j argument."
|
|
|
|
% (cpu_count, safer_cpu_count)
|
|
|
|
)
|
|
|
|
env.SetOption("num_jobs", safer_cpu_count)
|
|
|
|
|
|
|
|
# Process CPU architecture argument.
|
|
|
|
if env["arch"] == "":
|
|
|
|
# No architecture specified. Default to arm64 if building for Android,
|
|
|
|
# universal if building for macOS or iOS, wasm32 if building for web,
|
|
|
|
# otherwise default to the host architecture.
|
|
|
|
if env["platform"] in ["macos", "ios"]:
|
|
|
|
env["arch"] = "universal"
|
|
|
|
elif env["platform"] == "android":
|
|
|
|
env["arch"] = "arm64"
|
2023-10-15 10:01:45 +00:00
|
|
|
elif env["platform"] == "web":
|
2023-07-22 15:59:11 +00:00
|
|
|
env["arch"] = "wasm32"
|
|
|
|
else:
|
|
|
|
host_machine = platform.machine().lower()
|
|
|
|
if host_machine in architecture_array:
|
|
|
|
env["arch"] = host_machine
|
|
|
|
elif host_machine in architecture_aliases.keys():
|
|
|
|
env["arch"] = architecture_aliases[host_machine]
|
|
|
|
elif "86" in host_machine:
|
|
|
|
# Catches x86, i386, i486, i586, i686, etc.
|
|
|
|
env["arch"] = "x86_32"
|
|
|
|
else:
|
|
|
|
print("Unsupported CPU architecture: " + host_machine)
|
2023-09-09 08:55:53 +00:00
|
|
|
env.Exit(1)
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
print("Building for architecture " + env["arch"] + " on platform " + env["platform"])
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
# These defaults may be needed by platform tools
|
|
|
|
env.use_hot_reload = env.get("use_hot_reload", env["target"] != "template_release")
|
|
|
|
env.editor_build = env["target"] == "editor"
|
|
|
|
env.dev_build = env["dev_build"]
|
|
|
|
env.debug_features = env["target"] in ["editor", "template_debug"]
|
|
|
|
|
|
|
|
if env.dev_build:
|
|
|
|
opt_level = "none"
|
|
|
|
elif env.debug_features:
|
|
|
|
opt_level = "speed_trace"
|
|
|
|
else: # Release
|
|
|
|
opt_level = "speed"
|
|
|
|
|
|
|
|
env["optimize"] = ARGUMENTS.get("optimize", opt_level)
|
|
|
|
env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
|
2023-08-04 16:02:57 +00:00
|
|
|
|
2024-01-30 08:32:27 +00:00
|
|
|
tool = Tool(env["platform"], toolpath=get_platform_tools_paths(env))
|
2023-11-06 16:43:24 +00:00
|
|
|
|
|
|
|
if tool is None or not tool.exists(env):
|
|
|
|
raise ValueError("Required toolchain not found for platform " + env["platform"])
|
|
|
|
|
|
|
|
tool.generate(env)
|
2024-02-14 14:32:27 +00:00
|
|
|
|
2024-04-30 17:06:51 +00:00
|
|
|
if env["threads"]:
|
|
|
|
env.Append(CPPDEFINES=["THREADS_ENABLED"])
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
if env.use_hot_reload:
|
|
|
|
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])
|
|
|
|
|
|
|
|
if env.editor_build:
|
|
|
|
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
|
|
|
|
|
|
|
|
# Configuration of build targets:
|
|
|
|
# - Editor or template
|
|
|
|
# - Debug features (DEBUG_ENABLED code)
|
|
|
|
# - Dev only code (DEV_ENABLED code)
|
|
|
|
# - Optimization level
|
|
|
|
# - Debug symbols for crash traces / debuggers
|
|
|
|
# Keep this configuration in sync with SConstruct in upstream Godot.
|
|
|
|
if env.debug_features:
|
|
|
|
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
|
|
|
|
# to give *users* extra debugging information for their game development.
|
|
|
|
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
|
|
|
|
# In upstream Godot this is added in typedefs.h when DEBUG_ENABLED is set.
|
|
|
|
env.Append(CPPDEFINES=["DEBUG_METHODS_ENABLED"])
|
|
|
|
|
|
|
|
if env.dev_build:
|
|
|
|
# DEV_ENABLED enables *engine developer* code which should only be compiled for those
|
|
|
|
# working on the engine itself.
|
|
|
|
env.Append(CPPDEFINES=["DEV_ENABLED"])
|
2023-07-22 15:59:11 +00:00
|
|
|
else:
|
2024-02-14 14:32:27 +00:00
|
|
|
# Disable assert() for production targets (only used in thirdparty code).
|
|
|
|
env.Append(CPPDEFINES=["NDEBUG"])
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
if env["precision"] == "double":
|
|
|
|
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
|
|
|
|
|
2023-12-17 17:45:31 +00:00
|
|
|
# Allow detecting when building as a GDExtension.
|
|
|
|
env.Append(CPPDEFINES=["GDEXTENSION"])
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
# Suffix
|
|
|
|
suffix = ".{}.{}".format(env["platform"], env["target"])
|
|
|
|
if env.dev_build:
|
|
|
|
suffix += ".dev"
|
|
|
|
if env["precision"] == "double":
|
|
|
|
suffix += ".double"
|
|
|
|
suffix += "." + env["arch"]
|
|
|
|
if env["ios_simulator"]:
|
|
|
|
suffix += ".simulator"
|
2024-04-30 17:06:51 +00:00
|
|
|
if not env["threads"]:
|
|
|
|
suffix += ".nothreads"
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
env["suffix"] = suffix # Exposed when included from another project
|
|
|
|
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
|
|
|
|
|
|
|
|
# compile_commands.json
|
2023-09-04 19:00:42 +00:00
|
|
|
env.Tool("compilation_db")
|
|
|
|
env.Alias("compiledb", env.CompilationDatabase(normalize_path(env["compiledb_file"], env)))
|
2023-07-22 15:59:11 +00:00
|
|
|
|
2024-01-18 20:22:16 +00:00
|
|
|
# Formatting
|
|
|
|
if not env["verbose"]:
|
|
|
|
no_verbose(env)
|
|
|
|
|
2023-07-22 15:59:11 +00:00
|
|
|
# Builders
|
2024-01-18 20:22:16 +00:00
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
2024-01-25 14:54:58 +00:00
|
|
|
"GodotCPPBindings": Builder(action=Action(scons_generate_bindings, "$GENCOMSTR"), emitter=scons_emit_files),
|
|
|
|
"GodotCPPDocData": Builder(action=make_doc_source),
|
2024-01-18 20:22:16 +00:00
|
|
|
}
|
|
|
|
)
|
2023-07-22 15:59:11 +00:00
|
|
|
env.AddMethod(_godot_cpp, "GodotCPP")
|
2024-11-13 22:02:15 +00:00
|
|
|
env.AddMethod(_installable, "InstallableGodotCPP")
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _godot_cpp(env):
|
|
|
|
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
|
2023-10-02 18:31:06 +00:00
|
|
|
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
|
2023-07-22 15:59:11 +00:00
|
|
|
bindings = env.GodotCPPBindings(
|
|
|
|
env.Dir("."),
|
|
|
|
[
|
|
|
|
api_file,
|
|
|
|
os.path.join(extension_dir, "gdextension_interface.h"),
|
|
|
|
"binding_generator.py",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
# Forces bindings regeneration.
|
|
|
|
if env["generate_bindings"]:
|
2023-09-09 08:55:53 +00:00
|
|
|
env.AlwaysBuild(bindings)
|
|
|
|
env.NoCache(bindings)
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
# Sources to compile
|
|
|
|
sources = []
|
|
|
|
add_sources(sources, "src", "cpp")
|
|
|
|
add_sources(sources, "src/classes", "cpp")
|
|
|
|
add_sources(sources, "src/core", "cpp")
|
|
|
|
add_sources(sources, "src/variant", "cpp")
|
|
|
|
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
|
|
|
|
|
|
|
|
# Includes
|
|
|
|
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
|
|
|
|
|
|
|
|
library = None
|
|
|
|
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
|
|
|
|
|
|
|
|
if env["build_library"]:
|
|
|
|
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
|
2024-09-30 16:26:06 +00:00
|
|
|
env.NoCache(library)
|
2023-09-04 19:00:42 +00:00
|
|
|
default_args = [library]
|
|
|
|
|
|
|
|
# Add compiledb if the option is set
|
|
|
|
if env.get("compiledb", False):
|
|
|
|
default_args += ["compiledb"]
|
|
|
|
|
|
|
|
env.Default(*default_args)
|
2023-07-22 15:59:11 +00:00
|
|
|
|
|
|
|
env.AppendUnique(LIBS=[env.File("bin/%s" % library_name)])
|
|
|
|
return library
|
2024-11-13 22:02:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _installable(env, library):
|
|
|
|
import itertools
|
|
|
|
import json
|
|
|
|
|
|
|
|
install_prefix_dir = env["install_prefix_dir"]
|
|
|
|
full_install_lib_dir = os.path.join(install_prefix_dir, env["install_lib_dir"])
|
|
|
|
full_install_include_dir = os.path.join(install_prefix_dir, env["install_include_dir"])
|
|
|
|
|
|
|
|
# Obtain the gdextension version
|
|
|
|
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
|
|
|
|
api_filename = normalize_path(
|
|
|
|
env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath),
|
|
|
|
env,
|
|
|
|
)
|
|
|
|
with open(api_filename, "r") as api_json_file:
|
|
|
|
api_data = json.load(api_json_file)
|
|
|
|
version_major = api_data["header"]["version_major"]
|
|
|
|
version_minor = api_data["header"]["version_minor"]
|
|
|
|
version_patch = api_data["header"]["version_patch"]
|
|
|
|
gd_version = f"{version_major}.{version_minor}.{version_patch}"
|
|
|
|
|
|
|
|
# Configure and install the pkgconfig file
|
|
|
|
libname = str(library[0])
|
|
|
|
pkgconfig = env.Substfile(
|
|
|
|
target="gen/godot-cpp.pc",
|
|
|
|
source="cmake/godot-cpp.pc.in",
|
|
|
|
SUBST_DICT={
|
|
|
|
"@CMAKE_INSTALL_PREFIX@": install_prefix_dir,
|
|
|
|
"@CMAKE_INSTALL_FULL_INCLUDEDIR@": full_install_include_dir,
|
|
|
|
"@CMAKE_INSTALL_FULL_LIBDIR@": full_install_lib_dir,
|
|
|
|
"@GODOT_API_VERSION@": gd_version,
|
|
|
|
"@GODOTCPP_OUTPUT_NAME@": libname,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
full_install_pkgconfig_dir = os.path.join(full_install_lib_dir, "pkgconfig")
|
|
|
|
env.Install(full_install_pkgconfig_dir, pkgconfig)
|
|
|
|
|
|
|
|
# Install the headers
|
|
|
|
headers_from = []
|
|
|
|
headers_to = []
|
|
|
|
for dir_from, _, file_lst in itertools.chain(os.walk("include/godot_cpp"), os.walk("gen/include/godot_cpp")):
|
|
|
|
dir_to = os.path.join(full_install_include_dir, dir_from[dir_from.find("/godot_cpp") + 1 :])
|
|
|
|
headers_from += [os.path.join(dir_from, filename) for filename in file_lst]
|
|
|
|
headers_to += [os.path.join(dir_to, filename) for filename in file_lst]
|
|
|
|
env.InstallAs(headers_to, headers_from)
|
|
|
|
# Install the gdextension files
|
|
|
|
interface_header = os.path.join(extension_dir, "gdextension_interface.h")
|
|
|
|
env.Install(full_install_include_dir, interface_header)
|
|
|
|
|
|
|
|
# Install the static library
|
|
|
|
env.Install(full_install_lib_dir, library)
|
|
|
|
|
|
|
|
env.Alias("install", env["install_prefix_dir"])
|