| 1 |
#!/usr/bin/env python |
| 2 |
from misc.utility.scons_hints import * |
| 3 |
|
| 4 |
EnsureSConsVersion(4, 0) |
| 5 |
EnsurePythonVersion(3, 8) |
| 6 |
|
| 7 |
# System |
| 8 |
import glob |
| 9 |
import os |
| 10 |
import pickle |
| 11 |
import sys |
| 12 |
from collections import OrderedDict |
| 13 |
from importlib.util import module_from_spec, spec_from_file_location |
| 14 |
from types import ModuleType |
| 15 |
|
| 16 |
from SCons import __version__ as scons_raw_version |
| 17 |
from SCons.Builder import ListEmitter |
| 18 |
|
| 19 |
# Explicitly resolve the helper modules, this is done to avoid clash with |
| 20 |
# modules of the same name that might be randomly added (e.g. someone adding |
| 21 |
# an `editor.py` file at the root of the module creates a clash with the editor |
| 22 |
# folder when doing `import editor.template_builder`) |
| 23 |
|
| 24 |
|
| 25 |
def _helper_module(name, path): |
| 26 |
spec = spec_from_file_location(name, path) |
| 27 |
module = module_from_spec(spec) |
| 28 |
spec.loader.exec_module(module) |
| 29 |
sys.modules[name] = module |
| 30 |
# Ensure the module's parents are in loaded to avoid loading the wrong parent |
| 31 |
# when doing "import foo.bar" while only "foo.bar" as declared as helper module |
| 32 |
child_module = module |
| 33 |
parent_name = name |
| 34 |
while True: |
| 35 |
try: |
| 36 |
parent_name, child_name = parent_name.rsplit(".", 1) |
| 37 |
except ValueError: |
| 38 |
break |
| 39 |
try: |
| 40 |
parent_module = sys.modules[parent_name] |
| 41 |
except KeyError: |
| 42 |
parent_module = ModuleType(parent_name) |
| 43 |
sys.modules[parent_name] = parent_module |
| 44 |
setattr(parent_module, child_name, child_module) |
| 45 |
|
| 46 |
|
| 47 |
_helper_module("gles3_builders", "gles3_builders.py") |
| 48 |
_helper_module("glsl_builders", "glsl_builders.py") |
| 49 |
_helper_module("methods", "methods.py") |
| 50 |
_helper_module("platform_methods", "platform_methods.py") |
| 51 |
_helper_module("version", "version.py") |
| 52 |
_helper_module("core.core_builders", "core/core_builders.py") |
| 53 |
_helper_module("main.main_builders", "main/main_builders.py") |
| 54 |
_helper_module("misc.utility.color", "misc/utility/color.py") |
| 55 |
|
| 56 |
# Local |
| 57 |
import gles3_builders |
| 58 |
import glsl_builders |
| 59 |
import methods |
| 60 |
import scu_builders |
| 61 |
from misc.utility.color import is_stderr_color, print_error, print_info, print_warning |
| 62 |
from platform_methods import architecture_aliases, architectures, compatibility_platform_aliases |
| 63 |
|
| 64 |
if ARGUMENTS.get("target", "editor") == "editor": |
| 65 |
_helper_module("editor.editor_builders", "editor/editor_builders.py") |
| 66 |
_helper_module("editor.template_builders", "editor/template_builders.py") |
| 67 |
|
| 68 |
# Scan possible build platforms |
| 69 |
|
| 70 |
platform_list = [] # list of platforms |
| 71 |
platform_opts = {} # options for each platform |
| 72 |
platform_flags = {} # flags for each platform |
| 73 |
platform_doc_class_path = {} |
| 74 |
platform_exporters = [] |
| 75 |
platform_apis = [] |
| 76 |
|
| 77 |
for x in sorted(glob.glob("platform/*")): |
| 78 |
if not os.path.isdir(x) or not os.path.exists(x + "/detect.py"): |
| 79 |
continue |
| 80 |
tmppath = "./" + x |
| 81 |
|
| 82 |
sys.path.insert(0, tmppath) |
| 83 |
import detect |
| 84 |
|
| 85 |
# Get doc classes paths (if present) |
| 86 |
try: |
| 87 |
doc_classes = detect.get_doc_classes() |
| 88 |
doc_path = detect.get_doc_path() |
| 89 |
for c in doc_classes: |
| 90 |
platform_doc_class_path[c] = x.replace("\\", "/") + "/" + doc_path |
| 91 |
except Exception: |
| 92 |
pass |
| 93 |
|
| 94 |
platform_name = x[9:] |
| 95 |
|
| 96 |
if os.path.exists(x + "/export/export.cpp"): |
| 97 |
platform_exporters.append(platform_name) |
| 98 |
if os.path.exists(x + "/api/api.cpp"): |
| 99 |
platform_apis.append(platform_name) |
| 100 |
if detect.can_build(): |
| 101 |
x = x.replace("platform/", "") # rest of world |
| 102 |
x = x.replace("platform\\", "") # win32 |
| 103 |
platform_list += [x] |
| 104 |
platform_opts[x] = detect.get_opts() |
| 105 |
platform_flags[x] = detect.get_flags() |
| 106 |
if isinstance(platform_flags[x], list): # backwards compatibility |
| 107 |
platform_flags[x] = {flag[0]: flag[1] for flag in platform_flags[x]} |
| 108 |
sys.path.remove(tmppath) |
| 109 |
sys.modules.pop("detect") |
| 110 |
|
| 111 |
# We let SCons build its default ENV as it includes OS-specific things which we don't |
| 112 |
# want to have to pull in manually. However we enforce no "tools", which we register |
| 113 |
# further down after parsing our platform-specific configuration. |
| 114 |
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries. |
| 115 |
env = Environment(tools=[]) |
| 116 |
env.PrependENVPath("PATH", os.getenv("PATH")) |
| 117 |
env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH")) |
| 118 |
if "TERM" in os.environ: # Used for colored output. |
| 119 |
env["ENV"]["TERM"] = os.environ["TERM"] |
| 120 |
|
| 121 |
env.disabled_modules = set() |
| 122 |
env.module_version_string = "" |
| 123 |
env.msvc = False |
| 124 |
env.scons_version = env._get_major_minor_revision(scons_raw_version) |
| 125 |
|
| 126 |
env.__class__.add_module_version_string = methods.add_module_version_string |
| 127 |
|
| 128 |
env.__class__.add_source_files = methods.add_source_files |
| 129 |
env.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix |
| 130 |
|
| 131 |
env.__class__.add_shared_library = methods.add_shared_library |
| 132 |
env.__class__.add_library = methods.add_library |
| 133 |
env.__class__.add_program = methods.add_program |
| 134 |
env.__class__.CommandNoCache = methods.CommandNoCache |
| 135 |
env.__class__.Run = methods.Run |
| 136 |
env.__class__.disable_warnings = methods.disable_warnings |
| 137 |
env.__class__.force_optimization_on_debug = methods.force_optimization_on_debug |
| 138 |
env.__class__.module_add_dependencies = methods.module_add_dependencies |
| 139 |
env.__class__.module_check_dependencies = methods.module_check_dependencies |
| 140 |
|
| 141 |
env["x86_libtheora_opt_gcc"] = False |
| 142 |
env["x86_libtheora_opt_vc"] = False |
| 143 |
|
| 144 |
# avoid issues when building with different versions of python out of the same directory |
| 145 |
env.SConsignFile(File("#.sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL)).abspath) |
| 146 |
|
| 147 |
# Build options |
| 148 |
|
| 149 |
customs = ["custom.py"] |
| 150 |
|
| 151 |
profile = ARGUMENTS.get("profile", "") |
| 152 |
if profile: |
| 153 |
if os.path.isfile(profile): |
| 154 |
customs.append(profile) |
| 155 |
elif os.path.isfile(profile + ".py"): |
| 156 |
customs.append(profile + ".py") |
| 157 |
|
| 158 |
opts = Variables(customs, ARGUMENTS) |
| 159 |
|
| 160 |
# Target build options |
| 161 |
opts.Add((["platform", "p"], "Target platform (%s)" % "|".join(platform_list), "")) |
| 162 |
opts.Add( |
| 163 |
EnumVariable( |
| 164 |
"target", "Compilation target", "editor", ["editor", "template_release", "template_debug"], ignorecase=2 |
| 165 |
) |
| 166 |
) |
| 167 |
opts.Add(EnumVariable("arch", "CPU architecture", "auto", ["auto"] + architectures, architecture_aliases, ignorecase=2)) |
| 168 |
opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False)) |
| 169 |
opts.Add( |
| 170 |
EnumVariable( |
| 171 |
"optimize", |
| 172 |
"Optimization level (by default inferred from 'target' and 'dev_build')", |
| 173 |
"auto", |
| 174 |
["auto", "none", "custom", "debug", "speed", "speed_trace", "size", "size_extra"], |
| 175 |
ignorecase=2, |
| 176 |
) |
| 177 |
) |
| 178 |
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", False)) |
| 179 |
opts.Add(BoolVariable("separate_debug_symbols", "Extract debugging symbols to a separate file", False)) |
| 180 |
opts.Add(BoolVariable("debug_paths_relative", "Make file paths in debug symbols relative (if supported)", False)) |
| 181 |
opts.Add( |
| 182 |
EnumVariable( |
| 183 |
"lto", "Link-time optimization (production builds)", "none", ["none", "auto", "thin", "full"], ignorecase=2 |
| 184 |
) |
| 185 |
) |
| 186 |
opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False)) |
| 187 |
opts.Add(BoolVariable("threads", "Enable threading support", True)) |
| 188 |
|
| 189 |
# Components |
| 190 |
opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True)) |
| 191 |
opts.Add( |
| 192 |
EnumVariable("precision", "Set the floating-point precision level", "single", ["single", "double"], ignorecase=2) |
| 193 |
) |
| 194 |
opts.Add(BoolVariable("minizip", "Enable ZIP archive support using minizip", True)) |
| 195 |
opts.Add(BoolVariable("brotli", "Enable Brotli for decompression and WOFF2 fonts support", True)) |
| 196 |
opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver on supported platforms", False)) |
| 197 |
opts.Add(BoolVariable("vulkan", "Enable the Vulkan rendering driver", True)) |
| 198 |
opts.Add(BoolVariable("opengl3", "Enable the OpenGL/GLES3 rendering driver", True)) |
| 199 |
opts.Add(BoolVariable("d3d12", "Enable the Direct3D 12 rendering driver on supported platforms", False)) |
| 200 |
opts.Add(BoolVariable("metal", "Enable the Metal rendering driver on supported platforms (Apple arm64 only)", False)) |
| 201 |
opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True)) |
| 202 |
opts.Add(BoolVariable("accesskit", "Use AccessKit C SDK", True)) |
| 203 |
opts.Add(("accesskit_sdk_path", "Path to the AccessKit C SDK", "")) |
| 204 |
opts.Add(BoolVariable("sdl", "Enable the SDL3 input driver", True)) |
| 205 |
opts.Add( |
| 206 |
EnumVariable( |
| 207 |
"profiler", "Specify the profiler to use", "none", ["none", "tracy", "perfetto", "instruments"], ignorecase=2 |
| 208 |
) |
| 209 |
) |
| 210 |
opts.Add(("profiler_path", "Path to the Profiler framework.", "")) |
| 211 |
opts.Add( |
| 212 |
BoolVariable( |
| 213 |
"profiler_sample_callstack", |
| 214 |
"Profile random samples application-wide using a callstack based sampler.", |
| 215 |
False, |
| 216 |
) |
| 217 |
) |
| 218 |
opts.Add( |
| 219 |
BoolVariable( |
| 220 |
"profiler_track_memory", |
| 221 |
"Profile memory allocations, if the profiler supports it.", |
| 222 |
False, |
| 223 |
) |
| 224 |
) |
| 225 |
|
| 226 |
|
| 227 |
# Advanced options |
| 228 |
opts.Add( |
| 229 |
BoolVariable( |
| 230 |
"dev_mode", "Alias for dev options: verbose=yes warnings=extra werror=yes tests=yes strict_checks=yes", False |
| 231 |
) |
| 232 |
) |
| 233 |
opts.Add(BoolVariable("tests", "Build the unit tests", False)) |
| 234 |
opts.Add(BoolVariable("fast_unsafe", "Enable unsafe options for faster incremental builds", False)) |
| 235 |
opts.Add(BoolVariable("ninja", "Use the ninja backend for faster rebuilds", False)) |
| 236 |
opts.Add(BoolVariable("ninja_auto_run", "Run ninja automatically after generating the ninja file", True)) |
| 237 |
opts.Add("ninja_file", "Path to the generated ninja file", "build.ninja") |
| 238 |
opts.Add(BoolVariable("compiledb", "Generate compilation DB (`compile_commands.json`) for external tools", False)) |
| 239 |
opts.Add( |
| 240 |
"num_jobs", |
| 241 |
"Use up to N jobs when compiling (equivalent to `-j N`). Defaults to max jobs - 1. Ignored if -j is used.", |
| 242 |
"", |
| 243 |
) |
| 244 |
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False)) |
| 245 |
opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True)) |
| 246 |
opts.Add( |
| 247 |
EnumVariable("warnings", "Level of compilation warnings", "all", ["extra", "all", "moderate", "no"], ignorecase=2) |
| 248 |
) |
| 249 |
opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", False)) |
| 250 |
opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "") |
| 251 |
opts.Add("object_prefix", "Custom prefix added to the base filename of all generated object files", "") |
| 252 |
opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False)) |
| 253 |
opts.Add("vsproj_name", "Name of the Visual Studio solution", "godot") |
| 254 |
opts.Add("import_env_vars", "A comma-separated list of environment variables to copy from the outer environment.", "") |
| 255 |
opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True)) |
| 256 |
opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable", False)) |
| 257 |
opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False)) |
| 258 |
opts.Add(BoolVariable("disable_physics_2d", "Disable 2D physics nodes and server", False)) |
| 259 |
opts.Add(BoolVariable("disable_physics_3d", "Disable 3D physics nodes and server", False)) |
| 260 |
opts.Add(BoolVariable("disable_navigation_2d", "Disable 2D navigation features", False)) |
| 261 |
opts.Add(BoolVariable("disable_navigation_3d", "Disable 3D navigation features", False)) |
| 262 |
opts.Add(BoolVariable("disable_xr", "Disable XR nodes and server", False)) |
| 263 |
opts.Add(BoolVariable("disable_overrides", "Disable project settings overrides (override.cfg)", False)) |
| 264 |
opts.Add( |
| 265 |
BoolVariable( |
| 266 |
"disable_path_overrides", |
| 267 |
"Disable CLI arguments to override project path/main pack/scene and run scripts (export template only)", |
| 268 |
True, |
| 269 |
) |
| 270 |
) |
| 271 |
opts.Add("build_profile", "Path to a file containing a feature build profile", "") |
| 272 |
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "") |
| 273 |
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True)) |
| 274 |
opts.Add(BoolVariable("modules_enabled_by_default", "If no, disable all modules except ones explicitly enabled", True)) |
| 275 |
opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", True)) |
| 276 |
opts.Add( |
| 277 |
"system_certs_path", |
| 278 |
"Use this path as TLS certificates default for editor and Linux/BSD export templates (for package maintainers)", |
| 279 |
"", |
| 280 |
) |
| 281 |
opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False)) |
| 282 |
opts.Add(BoolVariable("strict_checks", "Enforce stricter checks (debug option)", False)) |
| 283 |
opts.Add( |
| 284 |
BoolVariable( |
| 285 |
"limit_transitive_includes", "Attempt to limit the amount of transitive includes in system headers", True |
| 286 |
) |
| 287 |
) |
| 288 |
opts.Add(BoolVariable("scu_build", "Use single compilation unit build", False)) |
| 289 |
opts.Add("scu_limit", "Max includes per SCU file when using scu_build (determines RAM use)", "0") |
| 290 |
opts.Add(BoolVariable("engine_update_check", "Enable engine update checks in the Project Manager", True)) |
| 291 |
opts.Add(BoolVariable("steamapi", "Enable minimal SteamAPI integration for usage time tracking (editor only)", False)) |
| 292 |
opts.Add("cache_path", "Path to a directory where SCons cache files will be stored. No value disables the cache.", "") |
| 293 |
opts.Add("cache_limit", "Max size (in GiB) for the SCons cache. 0 means no limit.", "0") |
| 294 |
opts.Add( |
| 295 |
BoolVariable( |
| 296 |
"redirect_build_objects", |
| 297 |
"Enable redirecting built objects/libraries to `bin/obj/` to declutter the repository.", |
| 298 |
True, |
| 299 |
) |
| 300 |
) |
| 301 |
opts.Add( |
| 302 |
EnumVariable( |
| 303 |
"library_type", |
| 304 |
"Build library type", |
| 305 |
"executable", |
| 306 |
("executable", "static_library", "shared_library"), |
| 307 |
) |
| 308 |
) |
| 309 |
|
| 310 |
# Thirdparty libraries |
| 311 |
opts.Add(BoolVariable("builtin_brotli", "Use the built-in Brotli library", True)) |
| 312 |
opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True)) |
| 313 |
opts.Add(BoolVariable("builtin_clipper2", "Use the built-in Clipper2 library", True)) |
| 314 |
opts.Add(BoolVariable("builtin_embree", "Use the built-in Embree library", True)) |
| 315 |
opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True)) |
| 316 |
opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True)) |
| 317 |
opts.Add(BoolVariable("builtin_msdfgen", "Use the built-in MSDFgen library", True)) |
| 318 |
opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True)) |
| 319 |
opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True)) |
| 320 |
opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True)) |
| 321 |
opts.Add(BoolVariable("builtin_sdl", "Use the built-in SDL library", True)) |
| 322 |
opts.Add(BoolVariable("builtin_icu4c", "Use the built-in ICU library", True)) |
| 323 |
opts.Add(BoolVariable("builtin_libjpeg_turbo", "Use the built-in libjpeg-turbo library", True)) |
| 324 |
opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True)) |
| 325 |
opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True)) |
| 326 |
opts.Add(BoolVariable("builtin_libtheora", "Use the built-in libtheora library", True)) |
| 327 |
opts.Add(BoolVariable("builtin_libvorbis", "Use the built-in libvorbis library", True)) |
| 328 |
opts.Add(BoolVariable("builtin_libwebp", "Use the built-in libwebp library", True)) |
| 329 |
opts.Add(BoolVariable("builtin_wslay", "Use the built-in wslay library", True)) |
| 330 |
opts.Add(BoolVariable("builtin_mbedtls", "Use the built-in mbedTLS library", True)) |
| 331 |
opts.Add(BoolVariable("builtin_miniupnpc", "Use the built-in miniupnpc library", True)) |
| 332 |
opts.Add(BoolVariable("builtin_openxr", "Use the built-in OpenXR library", True)) |
| 333 |
opts.Add(BoolVariable("builtin_pcre2", "Use the built-in PCRE2 library", True)) |
| 334 |
opts.Add(BoolVariable("builtin_pcre2_with_jit", "Use JIT compiler for the built-in PCRE2 library", True)) |
| 335 |
opts.Add(BoolVariable("builtin_recastnavigation", "Use the built-in Recast navigation library", True)) |
| 336 |
opts.Add(BoolVariable("builtin_rvo2_2d", "Use the built-in RVO2 2D library", True)) |
| 337 |
opts.Add(BoolVariable("builtin_rvo2_3d", "Use the built-in RVO2 3D library", True)) |
| 338 |
opts.Add(BoolVariable("builtin_xatlas", "Use the built-in xatlas library", True)) |
| 339 |
opts.Add(BoolVariable("builtin_zlib", "Use the built-in zlib library", True)) |
| 340 |
opts.Add(BoolVariable("builtin_zstd", "Use the built-in Zstd library", True)) |
| 341 |
|
| 342 |
# Compilation environment setup |
| 343 |
# CXX, CC, and LINK directly set the equivalent `env` values (which may still |
| 344 |
# be overridden for a specific platform), the lowercase ones are appended. |
| 345 |
opts.Add("CXX", "C++ compiler binary") |
| 346 |
opts.Add("CC", "C compiler binary") |
| 347 |
opts.Add("LINK", "Linker binary") |
| 348 |
opts.Add("cppdefines", "Custom defines for the pre-processor") |
| 349 |
opts.Add("ccflags", "Custom flags for both the C and C++ compilers") |
| 350 |
opts.Add("cxxflags", "Custom flags for the C++ compiler") |
| 351 |
opts.Add("cflags", "Custom flags for the C compiler") |
| 352 |
opts.Add("linkflags", "Custom flags for the linker") |
| 353 |
opts.Add("asflags", "Custom flags for the assembler") |
| 354 |
opts.Add("arflags", "Custom flags for the archive tool") |
| 355 |
opts.Add("rcflags", "Custom flags for Windows resource compiler") |
| 356 |
|
| 357 |
opts.Add("c_compiler_launcher", "C compiler launcher (e.g. `ccache`)") |
| 358 |
opts.Add("cpp_compiler_launcher", "C++ compiler launcher (e.g. `ccache`)") |
| 359 |
|
| 360 |
# Update the environment to have all above options defined |
| 361 |
# in following code (especially platform and custom_modules). |
| 362 |
opts.Update(env) |
| 363 |
|
| 364 |
# Setup caching logic early to catch everything. |
| 365 |
methods.prepare_cache(env) |
| 366 |
|
| 367 |
# Copy custom environment variables if set. |
| 368 |
if env["import_env_vars"]: |
| 369 |
for env_var in str(env["import_env_vars"]).split(","): |
| 370 |
if env_var in os.environ: |
| 371 |
env["ENV"][env_var] = os.environ[env_var] |
| 372 |
|
| 373 |
# Platform selection: validate input, and add options. |
| 374 |
|
| 375 |
if not env["platform"]: |
| 376 |
# Missing `platform` argument, try to detect platform automatically |
| 377 |
if ( |
| 378 |
sys.platform.startswith("linux") |
| 379 |
or sys.platform.startswith("dragonfly") |
| 380 |
or sys.platform.startswith("freebsd") |
| 381 |
or sys.platform.startswith("netbsd") |
| 382 |
or sys.platform.startswith("openbsd") |
| 383 |
): |
| 384 |
env["platform"] = "linuxbsd" |
| 385 |
elif sys.platform == "darwin": |
| 386 |
env["platform"] = "macos" |
| 387 |
elif sys.platform == "win32": |
| 388 |
env["platform"] = "windows" |
| 389 |
|
| 390 |
if env["platform"]: |
| 391 |
print(f"Automatically detected platform: {env['platform']}") |
| 392 |
|
| 393 |
# Deprecated aliases kept for compatibility. |
| 394 |
if env["platform"] in compatibility_platform_aliases: |
| 395 |
alias = env["platform"] |
| 396 |
platform = compatibility_platform_aliases[alias] |
| 397 |
print_warning( |
| 398 |
f'Platform "{alias}" has been renamed to "{platform}" in Godot 4. Building for platform "{platform}".' |
| 399 |
) |
| 400 |
env["platform"] = platform |
| 401 |
|
| 402 |
# Alias for convenience. |
| 403 |
if env["platform"] in ["linux", "bsd"]: |
| 404 |
env["platform"] = "linuxbsd" |
| 405 |
|
| 406 |
if env["platform"] not in platform_list: |
| 407 |
text = "The following platforms are available:\n\t{}\n".format("\n\t".join(platform_list)) |
| 408 |
text += "Please run SCons again and select a valid platform: platform=<string>." |
| 409 |
|
| 410 |
if env["platform"] == "list": |
| 411 |
print(text) |
| 412 |
elif not env["platform"]: |
| 413 |
print_error("Could not detect platform automatically.\n" + text) |
| 414 |
else: |
| 415 |
print_error(f'Invalid target platform "{env["platform"]}".\n' + text) |
| 416 |
|
| 417 |
Exit(0 if env["platform"] == "list" else 255) |
| 418 |
|
| 419 |
# Add platform-specific options. |
| 420 |
if env["platform"] in platform_opts: |
| 421 |
opts.AddVariables(*platform_opts[env["platform"]]) |
| 422 |
|
| 423 |
# Platform-specific flags. |
| 424 |
# These can sometimes override default options, so they need to be processed |
| 425 |
# as early as possible to ensure that we're using the correct values. |
| 426 |
flag_list = platform_flags[env["platform"]] |
| 427 |
for key, value in flag_list.items(): |
| 428 |
if key not in ARGUMENTS or ARGUMENTS[key] == "auto": # Allow command line to override platform flags |
| 429 |
env[key] = value |
| 430 |
|
| 431 |
# Update the environment to take platform-specific options into account. |
| 432 |
opts.Update(env, {**ARGUMENTS, **env.Dictionary()}) |
| 433 |
|
| 434 |
# Detect modules. |
| 435 |
modules_detected = OrderedDict() |
| 436 |
module_search_paths = ["modules"] # Built-in path. |
| 437 |
|
| 438 |
if env["custom_modules"]: |
| 439 |
paths = env["custom_modules"].split(",") |
| 440 |
for p in paths: |
| 441 |
try: |
| 442 |
module_search_paths.append(methods.convert_custom_modules_path(p)) |
| 443 |
except ValueError as e: |
| 444 |
print_error(e) |
| 445 |
Exit(255) |
| 446 |
|
| 447 |
for path in module_search_paths: |
| 448 |
if path == "modules": |
| 449 |
# Built-in modules don't have nested modules, |
| 450 |
# so save the time it takes to parse directories. |
| 451 |
modules = methods.detect_modules(path, recursive=False) |
| 452 |
else: # Custom. |
| 453 |
modules = methods.detect_modules(path, env["custom_modules_recursive"]) |
| 454 |
# Provide default include path for both the custom module search `path` |
| 455 |
# and the base directory containing custom modules, as it may be different |
| 456 |
# from the built-in "modules" name (e.g. "custom_modules/summator/summator.h"), |
| 457 |
# so it can be referenced simply as `#include "summator/summator.h"` |
| 458 |
# independently of where a module is located on user's filesystem. |
| 459 |
env.Prepend(CPPPATH=[path, os.path.dirname(path)]) |
| 460 |
# Note: custom modules can override built-in ones. |
| 461 |
modules_detected.update(modules) |
| 462 |
|
| 463 |
# Add module options. |
| 464 |
for name, path in modules_detected.items(): |
| 465 |
sys.path.insert(0, path) |
| 466 |
import config |
| 467 |
|
| 468 |
if env["modules_enabled_by_default"]: |
| 469 |
enabled = True |
| 470 |
try: |
| 471 |
enabled = config.is_enabled() |
| 472 |
except AttributeError: |
| 473 |
pass |
| 474 |
else: |
| 475 |
enabled = False |
| 476 |
|
| 477 |
opts.Add(BoolVariable(f"module_{name}_enabled", f"Enable module '{name}'", enabled)) |
| 478 |
|
| 479 |
# Add module-specific options. |
| 480 |
try: |
| 481 |
opts.AddVariables(*config.get_opts(env["platform"])) |
| 482 |
except AttributeError: |
| 483 |
pass |
| 484 |
|
| 485 |
sys.path.remove(path) |
| 486 |
sys.modules.pop("config") |
| 487 |
|
| 488 |
env.modules_detected = modules_detected |
| 489 |
|
| 490 |
# Update the environment again after all the module options are added. |
| 491 |
opts.Update(env, {**ARGUMENTS, **env.Dictionary()}) |
| 492 |
Help(opts.GenerateHelpText(env)) |
| 493 |
|
| 494 |
|
| 495 |
# FIXME: Tool assignment happening at this stage is a direct consequence of getting the platform logic AFTER the SCons |
| 496 |
# environment was already been constructed. Fixing this would require a broader refactor where all options are setup |
| 497 |
# ahead of time with native validator/converter functions. |
| 498 |
tmppath = "./platform/" + env["platform"] |
| 499 |
sys.path.insert(0, tmppath) |
| 500 |
import detect |
| 501 |
|
| 502 |
custom_tools = ["default"] |
| 503 |
try: # Platform custom tools are optional |
| 504 |
custom_tools = detect.get_tools(env) |
| 505 |
except AttributeError: |
| 506 |
pass |
| 507 |
for tool in custom_tools: |
| 508 |
env.Tool(tool) |
| 509 |
|
| 510 |
|
| 511 |
# Add default include paths. |
| 512 |
env.Prepend(CPPPATH=["#"]) |
| 513 |
|
| 514 |
# configure ENV for platform |
| 515 |
env.platform_exporters = platform_exporters |
| 516 |
env.platform_apis = platform_apis |
| 517 |
|
| 518 |
# Configuration of build targets: |
| 519 |
# - Editor or template |
| 520 |
# - Debug features (DEBUG_ENABLED code) |
| 521 |
# - Dev only code (DEV_ENABLED code) |
| 522 |
# - Optimization level |
| 523 |
# - Debug symbols for crash traces / debuggers |
| 524 |
|
| 525 |
env.editor_build = env["target"] == "editor" |
| 526 |
env.dev_build = env["dev_build"] |
| 527 |
env.debug_features = env["target"] in ["editor", "template_debug"] |
| 528 |
|
| 529 |
if env["optimize"] == "auto": |
| 530 |
if env.dev_build: |
| 531 |
opt_level = "none" |
| 532 |
elif env.debug_features: |
| 533 |
opt_level = "speed_trace" |
| 534 |
else: # Release |
| 535 |
opt_level = "speed" |
| 536 |
env["optimize"] = opt_level |
| 537 |
|
| 538 |
env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", env.dev_build) |
| 539 |
|
| 540 |
if env.editor_build: |
| 541 |
env.Append(CPPDEFINES=["TOOLS_ENABLED"]) |
| 542 |
|
| 543 |
if env.debug_features: |
| 544 |
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended |
| 545 |
# to give *users* extra debugging information for their game development. |
| 546 |
env.Append(CPPDEFINES=["DEBUG_ENABLED"]) |
| 547 |
|
| 548 |
if env.dev_build: |
| 549 |
# DEV_ENABLED enables *engine developer* code which should only be compiled for those |
| 550 |
# working on the engine itself. |
| 551 |
env.Append(CPPDEFINES=["DEV_ENABLED"]) |
| 552 |
else: |
| 553 |
# Disable assert() for production targets (only used in thirdparty code). |
| 554 |
env.Append(CPPDEFINES=["NDEBUG"]) |
| 555 |
|
| 556 |
# This is not part of fast_unsafe because the only downside it has compared to |
| 557 |
# the default is that SCons won't mark files that were changed in the last second |
| 558 |
# as different. This is unlikely to be a problem in any real situation as just booting |
| 559 |
# up scons takes more than that time. |
| 560 |
# Renamed to `content-timestamp` in SCons >= 4.2, keeping MD5 for compat. |
| 561 |
env.Decider("MD5-timestamp") |
| 562 |
|
| 563 |
# SCons speed optimization controlled by the `fast_unsafe` option, which provide |
| 564 |
# more than 10 s speed up for incremental rebuilds. |
| 565 |
# Unsafe as they reduce the certainty of rebuilding all changed files. |
| 566 |
# If you use it and run into corrupted incremental builds, try to turn it off. |
| 567 |
# Ref: https://github.com/SCons/scons/wiki/GoFastButton |
| 568 |
if env["fast_unsafe"]: |
| 569 |
env.SetOption("implicit_cache", 1) |
| 570 |
env.SetOption("max_drift", 60) |
| 571 |
|
| 572 |
if env["use_precise_math_checks"]: |
| 573 |
env.Append(CPPDEFINES=["PRECISE_MATH_CHECKS"]) |
| 574 |
|
| 575 |
if env.editor_build: |
| 576 |
if env["engine_update_check"]: |
| 577 |
env.Append(CPPDEFINES=["ENGINE_UPDATE_CHECK_ENABLED"]) |
| 578 |
|
| 579 |
if not env.File("#main/splash_editor.png").exists(): |
| 580 |
# Force disabling editor splash if missing. |
| 581 |
env["no_editor_splash"] = True |
| 582 |
if env["no_editor_splash"]: |
| 583 |
env.Append(CPPDEFINES=["NO_EDITOR_SPLASH"]) |
| 584 |
|
| 585 |
if not env["deprecated"]: |
| 586 |
env.Append(CPPDEFINES=["DISABLE_DEPRECATED"]) |
| 587 |
|
| 588 |
if env["precision"] == "double": |
| 589 |
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"]) |
| 590 |
|
| 591 |
# Library Support |
| 592 |
if env["library_type"] != "executable": |
| 593 |
if "library" not in env.get("supported", []): |
| 594 |
print_error(f"Library builds unsupported for {env['platform']}") |
| 595 |
Exit(255) |
| 596 |
env.Append(CPPDEFINES=["LIBGODOT_ENABLED"]) |
| 597 |
|
| 598 |
# Default num_jobs to local cpu count if not user specified. |
| 599 |
# SCons has a peculiarity where user-specified options won't be overridden |
| 600 |
# by SetOption, so we can rely on this to know if we should use our default. |
| 601 |
initial_num_jobs = env.GetOption("num_jobs") |
| 602 |
altered_num_jobs = initial_num_jobs + 1 |
| 603 |
env.SetOption("num_jobs", altered_num_jobs) |
| 604 |
if env.GetOption("num_jobs") == altered_num_jobs: |
| 605 |
num_jobs = env.get("num_jobs", "") |
| 606 |
if str(num_jobs).isdigit() and int(num_jobs) > 0: |
| 607 |
env.SetOption("num_jobs", num_jobs) |
| 608 |
else: |
| 609 |
cpu_count = os.cpu_count() |
| 610 |
if cpu_count is None: |
| 611 |
print_warning( |
| 612 |
"Couldn't auto-detect CPU count to configure build parallelism. Specify it with the `-j` or `num_jobs` arguments." |
| 613 |
) |
| 614 |
else: |
| 615 |
safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1 |
| 616 |
print( |
| 617 |
"Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the `-j` or `num_jobs` arguments." |
| 618 |
% (cpu_count, safer_cpu_count) |
| 619 |
) |
| 620 |
env.SetOption("num_jobs", safer_cpu_count) |
| 621 |
|
| 622 |
env.extra_suffix = "" |
| 623 |
|
| 624 |
if env["extra_suffix"] != "": |
| 625 |
env.extra_suffix += "." + env["extra_suffix"] |
| 626 |
|
| 627 |
# Environment flags |
| 628 |
env.Append(CPPDEFINES=env.get("cppdefines", "").split()) |
| 629 |
env.Append(CCFLAGS=env.get("ccflags", "").split()) |
| 630 |
env.Append(CXXFLAGS=env.get("cxxflags", "").split()) |
| 631 |
env.Append(CFLAGS=env.get("cflags", "").split()) |
| 632 |
env.Append(LINKFLAGS=env.get("linkflags", "").split()) |
| 633 |
env.Append(ASFLAGS=env.get("asflags", "").split()) |
| 634 |
env.Append(ARFLAGS=env.get("arflags", "").split()) |
| 635 |
env.Append(RCFLAGS=env.get("rcflags", "").split()) |
| 636 |
|
| 637 |
# Feature build profile |
| 638 |
env.disabled_classes = [] |
| 639 |
if env["build_profile"] != "": |
| 640 |
print(f'Using feature build profile: "{env["build_profile"]}"') |
| 641 |
import json |
| 642 |
|
| 643 |
try: |
| 644 |
ft = json.load(open(env["build_profile"], "r", encoding="utf-8")) |
| 645 |
if "disabled_classes" in ft: |
| 646 |
env.disabled_classes = ft["disabled_classes"] |
| 647 |
if "disabled_build_options" in ft: |
| 648 |
dbo = ft["disabled_build_options"] |
| 649 |
for c in dbo: |
| 650 |
env[c] = dbo[c] |
| 651 |
except json.JSONDecodeError: |
| 652 |
print_error(f'Failed to open feature build profile: "{env["build_profile"]}"') |
| 653 |
Exit(255) |
| 654 |
|
| 655 |
# 'dev_mode' and 'production' are aliases to set default options if they haven't been |
| 656 |
# set manually by the user. |
| 657 |
if env["dev_mode"]: |
| 658 |
env["verbose"] = methods.get_cmdline_bool("verbose", True) |
| 659 |
env["warnings"] = ARGUMENTS.get("warnings", "extra") |
| 660 |
env["werror"] = methods.get_cmdline_bool("werror", True) |
| 661 |
env["tests"] = methods.get_cmdline_bool("tests", True) |
| 662 |
env["strict_checks"] = methods.get_cmdline_bool("strict_checks", True) |
| 663 |
if env["production"]: |
| 664 |
env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True) |
| 665 |
env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False) |
| 666 |
if env["platform"] == "android": |
| 667 |
env["swappy"] = methods.get_cmdline_bool("swappy", True) |
| 668 |
# LTO "auto" means we handle the preferred option in each platform detect.py. |
| 669 |
env["lto"] = ARGUMENTS.get("lto", "auto") |
| 670 |
|
| 671 |
if env["strict_checks"]: |
| 672 |
env.Append(CPPDEFINES=["STRICT_CHECKS"]) |
| 673 |
|
| 674 |
# Run SCU file generation script if in a SCU build. |
| 675 |
if env["scu_build"]: |
| 676 |
env.Append(CPPDEFINES=["SCU_BUILD_ENABLED"]) |
| 677 |
max_includes_per_scu = 8 |
| 678 |
if env.dev_build: |
| 679 |
max_includes_per_scu = 1024 |
| 680 |
|
| 681 |
read_scu_limit = int(env["scu_limit"]) |
| 682 |
read_scu_limit = max(0, min(read_scu_limit, 1024)) |
| 683 |
if read_scu_limit != 0: |
| 684 |
max_includes_per_scu = read_scu_limit |
| 685 |
|
| 686 |
methods.set_scu_folders(scu_builders.generate_scu_files(max_includes_per_scu)) |
| 687 |
|
| 688 |
# Must happen after the flags' definition, as configure is when most flags |
| 689 |
# are actually handled to change compile options, etc. |
| 690 |
detect.configure(env) |
| 691 |
|
| 692 |
platform_string = env["platform"] |
| 693 |
if env.get("simulator"): |
| 694 |
platform_string += " (simulator)" |
| 695 |
print(f'Building for platform "{platform_string}", architecture "{env["arch"]}", target "{env["target"]}".') |
| 696 |
|
| 697 |
if env.dev_build: |
| 698 |
print_info("Developer build, with debug optimization level and debug symbols (unless overridden).") |
| 699 |
|
| 700 |
# Enforce our minimal compiler version requirements |
| 701 |
cc_version = methods.get_compiler_version(env) |
| 702 |
cc_version_major = cc_version["major"] |
| 703 |
cc_version_minor = cc_version["minor"] |
| 704 |
cc_version_metadata1 = cc_version["metadata1"] |
| 705 |
|
| 706 |
if cc_version_major == -1: |
| 707 |
print_warning( |
| 708 |
"Couldn't detect compiler version, skipping version checks. " |
| 709 |
"Build may fail if the compiler doesn't support C++17 fully." |
| 710 |
) |
| 711 |
elif methods.using_gcc(env): |
| 712 |
if cc_version_major < 9: |
| 713 |
print_error( |
| 714 |
"Detected GCC version older than 9, which does not fully support " |
| 715 |
"C++17, or has bugs when compiling Godot. Supported versions are 9 " |
| 716 |
"and later. Use a newer GCC version, or Clang 6 or later by passing " |
| 717 |
'"use_llvm=yes" to the SCons command line.' |
| 718 |
) |
| 719 |
Exit(255) |
| 720 |
elif cc_version_metadata1 == "win32": |
| 721 |
print_error( |
| 722 |
"Detected mingw version is not using posix threads. Only posix " |
| 723 |
"version of mingw is supported. " |
| 724 |
'Use "update-alternatives --config x86_64-w64-mingw32-g++" ' |
| 725 |
"to switch to posix threads." |
| 726 |
) |
| 727 |
Exit(255) |
| 728 |
elif methods.using_clang(env): |
| 729 |
# Apple LLVM versions differ from upstream LLVM version \o/, compare |
| 730 |
# in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions |
| 731 |
if methods.is_apple_clang(env): |
| 732 |
if cc_version_major < 16: |
| 733 |
print_error( |
| 734 |
"Detected Apple Clang version older than 16, supported versions are Apple Clang 16 (Xcode 16) and later." |
| 735 |
) |
| 736 |
Exit(255) |
| 737 |
else: |
| 738 |
if cc_version_major < 6: |
| 739 |
print_error( |
| 740 |
"Detected Clang version older than 6, which does not fully support " |
| 741 |
"C++17. Supported versions are Clang 6 and later." |
| 742 |
) |
| 743 |
Exit(255) |
| 744 |
elif env["debug_paths_relative"] and cc_version_major < 10: |
| 745 |
print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.") |
| 746 |
env["debug_paths_relative"] = False |
| 747 |
|
| 748 |
elif env.msvc: |
| 749 |
# Ensure latest minor builds of Visual Studio 2017/2019. |
| 750 |
# https://github.com/godotengine/godot/pull/94995#issuecomment-2336464574 |
| 751 |
if cc_version_major == 16 and cc_version_minor < 11: |
| 752 |
print_error( |
| 753 |
"Detected Visual Studio 2019 version older than 16.11, which has bugs " |
| 754 |
"when compiling Godot. Use a newer VS2019 version, or VS2022." |
| 755 |
) |
| 756 |
Exit(255) |
| 757 |
if cc_version_major == 15 and cc_version_minor < 9: |
| 758 |
print_error( |
| 759 |
"Detected Visual Studio 2017 version older than 15.9, which has bugs " |
| 760 |
"when compiling Godot. Use a newer VS2017 version, or VS2019/VS2022." |
| 761 |
) |
| 762 |
Exit(255) |
| 763 |
if cc_version_major < 15: |
| 764 |
print_error( |
| 765 |
"Detected Visual Studio 2015 or earlier, which is unsupported in Godot. " |
| 766 |
"Supported versions are Visual Studio 2017 and later." |
| 767 |
) |
| 768 |
Exit(255) |
| 769 |
|
| 770 |
# Set x86 CPU instruction sets to use by the compiler's autovectorization. |
| 771 |
if env["arch"] == "x86_64": |
| 772 |
# On 64-bit x86, enable SSE 4.2 and prior instruction sets (SSE3/SSSE3/SSE4/SSE4.1) to improve performance. |
| 773 |
# This is supported on most CPUs released after 2009-2011 (Intel Nehalem, AMD Bulldozer). |
| 774 |
# AVX and AVX2 aren't enabled because they aren't available on more recent low-end Intel CPUs. |
| 775 |
if env.msvc and not methods.using_clang(env): |
| 776 |
# https://stackoverflow.com/questions/64053597/how-do-i-enable-sse4-1-and-sse3-but-not-avx-in-msvc/69328426 |
| 777 |
env.Append(CCFLAGS=["/d2archSSE42"]) |
| 778 |
else: |
| 779 |
# `-msse2` is implied when compiling for x86_64. |
| 780 |
env.Append(CCFLAGS=["-msse4.2", "-mpopcnt"]) |
| 781 |
elif env["arch"] == "x86_32": |
| 782 |
# Be more conservative with instruction sets on 32-bit x86 to improve compatibility. |
| 783 |
# SSE and SSE2 are present on all CPUs that support 64-bit, even if running a 32-bit OS. |
| 784 |
if env.msvc and not methods.using_clang(env): |
| 785 |
env.Append(CCFLAGS=["/arch:SSE2"]) |
| 786 |
else: |
| 787 |
# Use `-mfpmath=sse` to use SSE for floating-point math, which is more stable than x87. |
| 788 |
# `-mstackrealign` is needed for it to work. |
| 789 |
env.Append(CCFLAGS=["-msse2", "-mfpmath=sse", "-mstackrealign"]) |
| 790 |
|
| 791 |
# Explicitly specify colored output. |
| 792 |
if methods.using_gcc(env): |
| 793 |
env.AppendUnique(CCFLAGS=["-fdiagnostics-color" if is_stderr_color() else "-fno-diagnostics-color"]) |
| 794 |
elif methods.using_clang(env) or methods.using_emcc(env): |
| 795 |
env.AppendUnique(CCFLAGS=["-fcolor-diagnostics" if is_stderr_color() else "-fno-color-diagnostics"]) |
| 796 |
if sys.platform == "win32": |
| 797 |
env.AppendUnique(CCFLAGS=["-fansi-escape-codes"]) |
| 798 |
|
| 799 |
# Attempt to reduce transitive includes. |
| 800 |
if env["limit_transitive_includes"]: |
| 801 |
if not env.msvc: |
| 802 |
# FIXME: This define only affects `libcpp`, but lack of guaranteed, granular detection means |
| 803 |
# we're better off applying it universally. |
| 804 |
env.AppendUnique(CPPDEFINES=["_LIBCPP_REMOVE_TRANSITIVE_INCLUDES"]) |
| 805 |
|
| 806 |
# Set optimize and debug_symbols flags. |
| 807 |
# "custom" means do nothing and let users set their own optimization flags. |
| 808 |
# Needs to happen after configure to have `env.msvc` defined. |
| 809 |
env.AppendUnique(CCFLAGS=["$OPTIMIZELEVEL"]) |
| 810 |
if env.msvc: |
| 811 |
if env["debug_symbols"]: |
| 812 |
env.AppendUnique(CCFLAGS=["/Zi", "/FS"]) |
| 813 |
env.AppendUnique(LINKFLAGS=["/DEBUG:FULL"]) |
| 814 |
else: |
| 815 |
env.AppendUnique(LINKFLAGS=["/DEBUG:NONE"]) |
| 816 |
|
| 817 |
if env["optimize"].startswith("speed"): |
| 818 |
env["OPTIMIZELEVEL"] = "/O2" |
| 819 |
env.AppendUnique(LINKFLAGS=["/OPT:REF"]) |
| 820 |
if env["optimize"] == "speed_trace": |
| 821 |
env.AppendUnique(LINKFLAGS=["/OPT:NOICF"]) |
| 822 |
elif env["optimize"].startswith("size"): |
| 823 |
env["OPTIMIZELEVEL"] = "/O1" |
| 824 |
env.AppendUnique(LINKFLAGS=["/OPT:REF"]) |
| 825 |
if env["optimize"] == "size_extra": |
| 826 |
env.AppendUnique(CPPDEFINES=["SIZE_EXTRA"]) |
| 827 |
elif env["optimize"] == "debug" or env["optimize"] == "none": |
| 828 |
env["OPTIMIZELEVEL"] = "/Od" |
| 829 |
else: |
| 830 |
if env["debug_symbols"]: |
| 831 |
if env["platform"] == "windows": |
| 832 |
if methods.using_clang(env): |
| 833 |
env.AppendUnique(CCFLAGS=["-gdwarf-4"]) # clang dwarf-5 symbols are broken on Windows. |
| 834 |
else: |
| 835 |
env.AppendUnique(CCFLAGS=["-gdwarf-5"]) # For gcc, only dwarf-5 symbols seem usable by libbacktrace. |
| 836 |
else: |
| 837 |
# Adding dwarf-4 explicitly makes stacktraces work with clang builds, |
| 838 |
# otherwise addr2line doesn't understand them |
| 839 |
env.AppendUnique(CCFLAGS=["-gdwarf-4"]) |
| 840 |
if methods.using_emcc(env): |
| 841 |
# Emscripten only produces dwarf symbols when using "-g3". |
| 842 |
env.AppendUnique(CCFLAGS=["-g3"]) |
| 843 |
# Emscripten linker needs debug symbols options too. |
| 844 |
env.AppendUnique(LINKFLAGS=["-gdwarf-4"]) |
| 845 |
env.AppendUnique(LINKFLAGS=["-g3"]) |
| 846 |
elif env.dev_build: |
| 847 |
env.AppendUnique(CCFLAGS=["-g3"]) |
| 848 |
else: |
| 849 |
env.AppendUnique(CCFLAGS=["-g2"]) |
| 850 |
if env["debug_paths_relative"]: |
| 851 |
# Remap absolute paths to relative paths for debug symbols. |
| 852 |
project_path = Dir("#").abspath |
| 853 |
env.AppendUnique(CCFLAGS=[f"-ffile-prefix-map={project_path}=."]) |
| 854 |
else: |
| 855 |
if methods.is_apple_clang(env): |
| 856 |
# Apple Clang, its linker doesn't like -s. |
| 857 |
env.AppendUnique(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"]) |
| 858 |
else: |
| 859 |
env.AppendUnique(LINKFLAGS=["-s"]) |
| 860 |
|
| 861 |
# Linker needs optimization flags too, at least for Emscripten. |
| 862 |
# For other toolchains, this _may_ be useful for LTO too to disambiguate. |
| 863 |
env.AppendUnique(LINKFLAGS=["$OPTIMIZELEVEL"]) |
| 864 |
|
| 865 |
if env["optimize"] == "speed": |
| 866 |
env["OPTIMIZELEVEL"] = "-O3" |
| 867 |
# `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces. |
| 868 |
elif env["optimize"] == "speed_trace": |
| 869 |
env["OPTIMIZELEVEL"] = "-O2" |
| 870 |
elif env["optimize"].startswith("size"): |
| 871 |
env["OPTIMIZELEVEL"] = "-Os" |
| 872 |
if env["optimize"] == "size_extra": |
| 873 |
env.AppendUnique(CPPDEFINES=["SIZE_EXTRA"]) |
| 874 |
elif env["optimize"] == "debug": |
| 875 |
env["OPTIMIZELEVEL"] = "-Og" |
| 876 |
elif env["optimize"] == "none": |
| 877 |
env["OPTIMIZELEVEL"] = "-O0" |
| 878 |
|
| 879 |
# Needs to happen after configure to handle "auto". |
| 880 |
if env["lto"] != "none": |
| 881 |
print("Using LTO: " + env["lto"]) |
| 882 |
|
| 883 |
# Set our C and C++ standard requirements. |
| 884 |
# C++17 is required as we need guaranteed copy elision as per GH-36436. |
| 885 |
# Prepending to make it possible to override. |
| 886 |
# This needs to come after `configure`, otherwise we don't have env.msvc. |
| 887 |
if not env.msvc: |
| 888 |
# Specifying GNU extensions support explicitly, which are supported by |
| 889 |
# both GCC and Clang. Both currently default to gnu17 and gnu++17. |
| 890 |
env.Prepend(CFLAGS=["-std=gnu17"]) |
| 891 |
env.Prepend(CXXFLAGS=["-std=gnu++17"]) |
| 892 |
else: |
| 893 |
# MSVC started offering C standard support with Visual Studio 2019 16.8, which covers all |
| 894 |
# of our supported VS2019 & VS2022 versions; VS2017 will only pass the C++ standard. |
| 895 |
env.Prepend(CXXFLAGS=["/std:c++17"]) |
| 896 |
if cc_version_major < 16: |
| 897 |
print_warning("Visual Studio 2017 cannot specify a C-Standard.") |
| 898 |
else: |
| 899 |
env.Prepend(CFLAGS=["/std:c17"]) |
| 900 |
# MSVC is non-conforming with the C++ standard by default, so we enable more conformance. |
| 901 |
# Note that this is still not complete conformance, as certain Windows-related headers |
| 902 |
# don't compile under complete conformance. |
| 903 |
env.Prepend(CCFLAGS=["/permissive-"]) |
| 904 |
# Allow use of `__cplusplus` macro to determine C++ standard universally. |
| 905 |
env.Prepend(CXXFLAGS=["/Zc:__cplusplus"]) |
| 906 |
|
| 907 |
# Disable exception handling. Godot doesn't use exceptions anywhere, and this |
| 908 |
# saves around 20% of binary size and very significant build time (GH-80513). |
| 909 |
if env["disable_exceptions"]: |
| 910 |
if env.msvc: |
| 911 |
env.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 0)]) |
| 912 |
else: |
| 913 |
env.Append(CXXFLAGS=["-fno-exceptions"]) |
| 914 |
elif env.msvc: |
| 915 |
env.Append(CXXFLAGS=["/EHsc"]) |
| 916 |
|
| 917 |
# Configure compiler warnings |
| 918 |
env.AppendUnique(CCFLAGS=["$WARNLEVEL"]) |
| 919 |
if env.msvc and not methods.using_clang(env): # MSVC |
| 920 |
# Disable warnings which we don't plan to fix. |
| 921 |
disabled_warnings = [ |
| 922 |
"/wd4100", # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism. |
| 923 |
"/wd4127", # C4127 (conditional expression is constant) |
| 924 |
"/wd4201", # C4201 (non-standard nameless struct/union): Only relevant for C89. |
| 925 |
"/wd4244", # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale. |
| 926 |
"/wd4245", |
| 927 |
"/wd4267", |
| 928 |
"/wd4305", # C4305 (truncation): double to float or real_t, too hard to avoid. |
| 929 |
"/wd4324", # C4820 (structure was padded due to alignment specifier) |
| 930 |
"/wd4514", # C4514 (unreferenced inline function has been removed) |
| 931 |
"/wd4714", # C4714 (function marked as __forceinline not inlined) |
| 932 |
"/wd4820", # C4820 (padding added after construct) |
| 933 |
] |
| 934 |
|
| 935 |
if env["warnings"] == "extra": |
| 936 |
env["WARNLEVEL"] = "/W4" |
| 937 |
env.AppendUnique(CCFLAGS=disabled_warnings) |
| 938 |
elif env["warnings"] == "all": |
| 939 |
env["WARNLEVEL"] = "/W3" |
| 940 |
# C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too. |
| 941 |
env.AppendUnique(CCFLAGS=["/w34458"] + disabled_warnings) |
| 942 |
elif env["warnings"] == "moderate": |
| 943 |
env["WARNLEVEL"] = "/W2" |
| 944 |
env.AppendUnique(CCFLAGS=disabled_warnings) |
| 945 |
else: # 'no' |
| 946 |
env["WARNLEVEL"] = "/w" |
| 947 |
# C4267 is particularly finicky & needs to be explicitly disabled. |
| 948 |
env.AppendUnique(CCFLAGS=["/wd4267"]) |
| 949 |
|
| 950 |
if env["werror"]: |
| 951 |
env.AppendUnique(CCFLAGS=["/WX"]) |
| 952 |
env.AppendUnique(LINKFLAGS=["/WX"]) |
| 953 |
|
| 954 |
else: # GCC, Clang |
| 955 |
common_warnings = [] |
| 956 |
if methods.using_gcc(env): |
| 957 |
common_warnings += ["-Wshadow", "-Wno-misleading-indentation"] |
| 958 |
if cc_version_major < 11: |
| 959 |
# Regression in GCC 9/10, spams so much in our variadic templates |
| 960 |
# that we need to outright disable it. |
| 961 |
common_warnings += ["-Wno-type-limits"] |
| 962 |
if cc_version_major == 12: |
| 963 |
# Regression in GCC 12, false positives in our error macros, see GH-58747. |
| 964 |
common_warnings += ["-Wno-return-type"] |
| 965 |
if cc_version_major >= 11: |
| 966 |
common_warnings += ["-Wenum-conversion"] |
| 967 |
if cc_version_major >= 16: |
| 968 |
# GCC 16 flags type-incompleteness assertions on their intended behavior, see GH-119269. |
| 969 |
env.AppendUnique(CXXFLAGS=["-Wno-sfinae-incomplete"]) |
| 970 |
elif methods.using_clang(env) or methods.using_emcc(env): |
| 971 |
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"] |
| 972 |
# We often implement `operator<` for structs of pointers as a requirement |
| 973 |
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering. |
| 974 |
common_warnings += ["-Wno-ordered-compare-function-pointers"] |
| 975 |
common_warnings += ["-Wenum-conversion"] |
| 976 |
|
| 977 |
# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast. |
| 978 |
env["WARNLEVEL"] = "-Wall" if not env.msvc else "-W3" |
| 979 |
|
| 980 |
if env["warnings"] == "extra": |
| 981 |
env.AppendUnique(CCFLAGS=["-Wextra", "-Wwrite-strings", "-Wno-unused-parameter"] + common_warnings) |
| 982 |
env.AppendUnique(CXXFLAGS=["-Wctor-dtor-privacy", "-Wnon-virtual-dtor"]) |
| 983 |
if methods.using_gcc(env): |
| 984 |
env.AppendUnique( |
| 985 |
CCFLAGS=[ |
| 986 |
"-Walloc-zero", |
| 987 |
"-Wduplicated-branches", |
| 988 |
"-Wduplicated-cond", |
| 989 |
"-Wstringop-overflow=4", |
| 990 |
] |
| 991 |
) |
| 992 |
env.AppendUnique(CXXFLAGS=["-Wplacement-new=1", "-Wvirtual-inheritance"]) |
| 993 |
# Need to fix a warning with AudioServer lambdas before enabling. |
| 994 |
# if cc_version_major != 9: # GCC 9 had a regression (GH-36325). |
| 995 |
# env.Append(CXXFLAGS=["-Wnoexcept"]) |
| 996 |
if cc_version_major >= 9: |
| 997 |
env.AppendUnique(CCFLAGS=["-Wattribute-alias=2"]) |
| 998 |
if cc_version_major >= 11: # Broke on MethodBind templates before GCC 11. |
| 999 |
env.AppendUnique(CCFLAGS=["-Wlogical-op"]) |
| 1000 |
elif methods.using_clang(env) or methods.using_emcc(env): |
| 1001 |
env.AppendUnique(CCFLAGS=["-Wimplicit-fallthrough"]) |
| 1002 |
elif env["warnings"] == "all": |
| 1003 |
env.AppendUnique(CCFLAGS=common_warnings) |
| 1004 |
elif env["warnings"] == "moderate": |
| 1005 |
env.AppendUnique(CCFLAGS=["-Wno-unused"] + common_warnings) |
| 1006 |
else: # 'no' |
| 1007 |
env["WARNLEVEL"] = "-w" |
| 1008 |
|
| 1009 |
if env["werror"]: |
| 1010 |
env.AppendUnique(CCFLAGS=["-Werror"]) |
| 1011 |
|
| 1012 |
if hasattr(detect, "get_program_suffix"): |
| 1013 |
suffix = "." + detect.get_program_suffix() |
| 1014 |
else: |
| 1015 |
suffix = "." + env["platform"] |
| 1016 |
|
| 1017 |
suffix += "." + env["target"] |
| 1018 |
if env.dev_build: |
| 1019 |
suffix += ".dev" |
| 1020 |
|
| 1021 |
if env["precision"] == "double": |
| 1022 |
suffix += ".double" |
| 1023 |
|
| 1024 |
suffix += "." + env["arch"] |
| 1025 |
|
| 1026 |
if not env["threads"]: |
| 1027 |
suffix += ".nothreads" |
| 1028 |
|
| 1029 |
suffix += env.extra_suffix |
| 1030 |
|
| 1031 |
sys.path.remove(tmppath) |
| 1032 |
sys.modules.pop("detect") |
| 1033 |
|
| 1034 |
if env.editor_build: |
| 1035 |
unsupported_opts = [] |
| 1036 |
for disable_opt in [ |
| 1037 |
"disable_3d", |
| 1038 |
"disable_advanced_gui", |
| 1039 |
"disable_physics_2d", |
| 1040 |
"disable_physics_3d", |
| 1041 |
"disable_navigation_2d", |
| 1042 |
"disable_navigation_3d", |
| 1043 |
]: |
| 1044 |
if env[disable_opt]: |
| 1045 |
unsupported_opts.append(disable_opt) |
| 1046 |
if unsupported_opts != []: |
| 1047 |
print_error( |
| 1048 |
"The following build option(s) cannot be used for editor builds, but only for export template builds: {}.".format( |
| 1049 |
", ".join(unsupported_opts) |
| 1050 |
) |
| 1051 |
) |
| 1052 |
Exit(255) |
| 1053 |
|
| 1054 |
if env["disable_3d"]: |
| 1055 |
env.Append(CPPDEFINES=["_3D_DISABLED"]) |
| 1056 |
env["disable_navigation_3d"] = True |
| 1057 |
env["disable_physics_3d"] = True |
| 1058 |
env["disable_xr"] = True |
| 1059 |
if env["disable_advanced_gui"]: |
| 1060 |
env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"]) |
| 1061 |
if env["disable_physics_2d"]: |
| 1062 |
env.Append(CPPDEFINES=["PHYSICS_2D_DISABLED"]) |
| 1063 |
if env["disable_physics_3d"]: |
| 1064 |
env.Append(CPPDEFINES=["PHYSICS_3D_DISABLED"]) |
| 1065 |
if env["disable_navigation_2d"]: |
| 1066 |
env.Append(CPPDEFINES=["NAVIGATION_2D_DISABLED"]) |
| 1067 |
if env["disable_navigation_3d"]: |
| 1068 |
env.Append(CPPDEFINES=["NAVIGATION_3D_DISABLED"]) |
| 1069 |
if env["disable_xr"]: |
| 1070 |
env.Append(CPPDEFINES=["XR_DISABLED"]) |
| 1071 |
if env["minizip"]: |
| 1072 |
env.Append(CPPDEFINES=["MINIZIP_ENABLED"]) |
| 1073 |
if env["brotli"]: |
| 1074 |
env.Append(CPPDEFINES=["BROTLI_ENABLED"]) |
| 1075 |
|
| 1076 |
if not env["disable_overrides"]: |
| 1077 |
env.Append(CPPDEFINES=["OVERRIDE_ENABLED"]) |
| 1078 |
|
| 1079 |
if env.editor_build or not env["disable_path_overrides"]: |
| 1080 |
env.Append(CPPDEFINES=["OVERRIDE_PATH_ENABLED"]) |
| 1081 |
|
| 1082 |
if not env["verbose"]: |
| 1083 |
methods.no_verbose(env) |
| 1084 |
|
| 1085 |
modules_enabled = OrderedDict() |
| 1086 |
env.module_dependencies = {} |
| 1087 |
env.module_icons_paths = [] |
| 1088 |
env.doc_class_path = platform_doc_class_path |
| 1089 |
|
| 1090 |
for name, path in modules_detected.items(): |
| 1091 |
if not env[f"module_{name}_enabled"]: |
| 1092 |
continue |
| 1093 |
sys.path.insert(0, path) |
| 1094 |
env.current_module = name |
| 1095 |
import config |
| 1096 |
|
| 1097 |
if config.can_build(env, env["platform"]): |
| 1098 |
# Disable it if a required dependency is missing. |
| 1099 |
if not env.module_check_dependencies(name): |
| 1100 |
continue |
| 1101 |
|
| 1102 |
config.configure(env) |
| 1103 |
# Get doc classes paths (if present) |
| 1104 |
try: |
| 1105 |
doc_classes = config.get_doc_classes() |
| 1106 |
doc_path = config.get_doc_path() |
| 1107 |
for c in doc_classes: |
| 1108 |
env.doc_class_path[c] = path + "/" + doc_path |
| 1109 |
except Exception: |
| 1110 |
pass |
| 1111 |
# Get icon paths (if present) |
| 1112 |
try: |
| 1113 |
icons_path = config.get_icons_path() |
| 1114 |
env.module_icons_paths.append(path + "/" + icons_path) |
| 1115 |
except Exception: |
| 1116 |
# Default path for module icons |
| 1117 |
env.module_icons_paths.append(path + "/" + "icons") |
| 1118 |
modules_enabled[name] = path |
| 1119 |
|
| 1120 |
sys.path.remove(path) |
| 1121 |
sys.modules.pop("config") |
| 1122 |
|
| 1123 |
env.module_list = modules_enabled |
| 1124 |
methods.sort_module_list(env) |
| 1125 |
|
| 1126 |
if env.editor_build: |
| 1127 |
# Add editor-specific dependencies to the dependency graph. |
| 1128 |
env.module_add_dependencies("editor", ["freetype", "regex", "svg"]) |
| 1129 |
|
| 1130 |
# And check if they are met. |
| 1131 |
if not env.module_check_dependencies("editor"): |
| 1132 |
print_error("Not all modules required by editor builds are enabled.") |
| 1133 |
Exit(255) |
| 1134 |
|
| 1135 |
env["PROGSUFFIX_WRAP"] = suffix + env.module_version_string + ".console" + env["PROGSUFFIX"] |
| 1136 |
env["PROGSUFFIX"] = suffix + env.module_version_string + env["PROGSUFFIX"] |
| 1137 |
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"] |
| 1138 |
# (SH)LIBSUFFIX will be used for our own built libraries |
| 1139 |
# LIBSUFFIXES contains LIBSUFFIX and SHLIBSUFFIX by default, |
| 1140 |
# so we need to append the default suffixes to keep the ability |
| 1141 |
# to link against thirdparty libraries (.a, .so, .lib, etc.). |
| 1142 |
if os.name == "nt": |
| 1143 |
# On Windows, only static libraries and import libraries can be |
| 1144 |
# statically linked - both using .lib extension |
| 1145 |
env["LIBSUFFIXES"] += [env["LIBSUFFIX"]] |
| 1146 |
else: |
| 1147 |
env["LIBSUFFIXES"] += [env["LIBSUFFIX"], env["SHLIBSUFFIX"]] |
| 1148 |
env["LIBSUFFIX"] = suffix + env["LIBSUFFIX"] |
| 1149 |
env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"] |
| 1150 |
|
| 1151 |
env["OBJPREFIX"] = env["object_prefix"] |
| 1152 |
env["SHOBJPREFIX"] = env["object_prefix"] |
| 1153 |
|
| 1154 |
GLSL_BUILDERS = { |
| 1155 |
"RD_GLSL": env.Builder( |
| 1156 |
action=env.Run(glsl_builders.build_rd_headers), |
| 1157 |
suffix="glsl.gen.h", |
| 1158 |
src_suffix=".glsl", |
| 1159 |
), |
| 1160 |
"GLSL_HEADER": env.Builder( |
| 1161 |
action=env.Run(glsl_builders.build_raw_headers), |
| 1162 |
suffix="glsl.gen.h", |
| 1163 |
src_suffix=".glsl", |
| 1164 |
), |
| 1165 |
"GLES3_GLSL": env.Builder( |
| 1166 |
action=env.Run(gles3_builders.build_gles3_headers), |
| 1167 |
suffix="glsl.gen.h", |
| 1168 |
src_suffix=".glsl", |
| 1169 |
), |
| 1170 |
} |
| 1171 |
env.Append(BUILDERS=GLSL_BUILDERS) |
| 1172 |
|
| 1173 |
if env["compiledb"]: |
| 1174 |
env.Tool("compilation_db") |
| 1175 |
env.Alias("compiledb", env.CompilationDatabase()) |
| 1176 |
env.NoCache(env.CompilationDatabase()) |
| 1177 |
if not env["verbose"]: |
| 1178 |
env["COMPILATIONDB_COMSTR"] = "$GENCOMSTR" |
| 1179 |
|
| 1180 |
if env["ninja"]: |
| 1181 |
if env.scons_version < (4, 2, 0): |
| 1182 |
print_error(f"The `ninja=yes` option requires SCons 4.2 or later, but your version is {scons_raw_version}.") |
| 1183 |
Exit(255) |
| 1184 |
|
| 1185 |
SetOption("experimental", "ninja") |
| 1186 |
env["NINJA_FILE_NAME"] = env["ninja_file"] |
| 1187 |
env["NINJA_DISABLE_AUTO_RUN"] = not env["ninja_auto_run"] |
| 1188 |
env.Tool("ninja", env["ninja_file"]) |
| 1189 |
|
| 1190 |
# Threads |
| 1191 |
if env["threads"]: |
| 1192 |
env.Append(CPPDEFINES=["THREADS_ENABLED"]) |
| 1193 |
|
| 1194 |
# Ensure build objects are put in their own folder if `redirect_build_objects` is enabled. |
| 1195 |
env.Prepend(LIBEMITTER=[methods.redirect_emitter]) |
| 1196 |
env.Prepend(SHLIBEMITTER=[methods.redirect_emitter]) |
| 1197 |
for key in (emitters := env.StaticObject.builder.emitter): |
| 1198 |
emitters[key] = ListEmitter([methods.redirect_emitter] + env.Flatten(emitters[key])) |
| 1199 |
for key in (emitters := env.SharedObject.builder.emitter): |
| 1200 |
emitters[key] = ListEmitter([methods.redirect_emitter] + env.Flatten(emitters[key])) |
| 1201 |
|
| 1202 |
# Prepend compiler launchers |
| 1203 |
if "c_compiler_launcher" in env: |
| 1204 |
env["CC"] = " ".join([env["c_compiler_launcher"], env["CC"]]) |
| 1205 |
|
| 1206 |
if "cpp_compiler_launcher" in env: |
| 1207 |
env["CXX"] = " ".join([env["cpp_compiler_launcher"], env["CXX"]]) |
| 1208 |
|
| 1209 |
# Build subdirs, the build order is dependent on link order. |
| 1210 |
Export("env") |
| 1211 |
|
| 1212 |
SConscript("core/SCsub") |
| 1213 |
SConscript("servers/SCsub") |
| 1214 |
SConscript("scene/SCsub") |
| 1215 |
if env.editor_build: |
| 1216 |
SConscript("editor/SCsub") |
| 1217 |
SConscript("drivers/SCsub") |
| 1218 |
|
| 1219 |
SConscript("platform/SCsub") |
| 1220 |
SConscript("modules/SCsub") |
| 1221 |
if env["tests"]: |
| 1222 |
SConscript("tests/SCsub") |
| 1223 |
SConscript("main/SCsub") |
| 1224 |
|
| 1225 |
SConscript("platform/" + env["platform"] + "/SCsub") # Build selected platform. |
| 1226 |
|
| 1227 |
# Microsoft Visual Studio Project Generation |
| 1228 |
if env["vsproj"]: |
| 1229 |
methods.generate_cpp_hint_file("cpp.hint") |
| 1230 |
env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]] |
| 1231 |
methods.generate_vs_project(env, ARGUMENTS, env["vsproj_name"]) |
| 1232 |
|
| 1233 |
# Miscellaneous & post-build methods. |
| 1234 |
if not env.GetOption("clean") and not env.GetOption("help"): |
| 1235 |
methods.dump(env) |
| 1236 |
methods.show_progress(env) |
| 1237 |
methods.prepare_purge(env) |
| 1238 |
methods.prepare_timer() |