SConstruct 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. #!/usr/bin/env python
  2. EnsureSConsVersion(3, 0, 0)
  3. EnsurePythonVersion(3, 5)
  4. # System
  5. import glob
  6. import os
  7. import pickle
  8. import sys
  9. from collections import OrderedDict
  10. # Local
  11. import methods
  12. import glsl_builders
  13. # Scan possible build platforms
  14. platform_list = [] # list of platforms
  15. platform_opts = {} # options for each platform
  16. platform_flags = {} # flags for each platform
  17. active_platforms = []
  18. active_platform_ids = []
  19. platform_exporters = []
  20. platform_apis = []
  21. for x in sorted(glob.glob("platform/*")):
  22. if not os.path.isdir(x) or not os.path.exists(x + "/detect.py"):
  23. continue
  24. tmppath = "./" + x
  25. sys.path.insert(0, tmppath)
  26. import detect
  27. if os.path.exists(x + "/export/export.cpp"):
  28. platform_exporters.append(x[9:])
  29. if os.path.exists(x + "/api/api.cpp"):
  30. platform_apis.append(x[9:])
  31. if detect.is_active():
  32. active_platforms.append(detect.get_name())
  33. active_platform_ids.append(x)
  34. if detect.can_build():
  35. x = x.replace("platform/", "") # rest of world
  36. x = x.replace("platform\\", "") # win32
  37. platform_list += [x]
  38. platform_opts[x] = detect.get_opts()
  39. platform_flags[x] = detect.get_flags()
  40. sys.path.remove(tmppath)
  41. sys.modules.pop("detect")
  42. methods.save_active_platforms(active_platforms, active_platform_ids)
  43. custom_tools = ["default"]
  44. platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))
  45. if os.name == "nt" and (platform_arg == "android" or methods.get_cmdline_bool("use_mingw", False)):
  46. custom_tools = ["mingw"]
  47. elif platform_arg == "javascript":
  48. # Use generic POSIX build toolchain for Emscripten.
  49. custom_tools = ["cc", "c++", "ar", "link", "textfile", "zip"]
  50. # We let SCons build its default ENV as it includes OS-specific things which we don't
  51. # want to have to pull in manually.
  52. # Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
  53. env_base = Environment(tools=custom_tools)
  54. env_base.PrependENVPath("PATH", os.getenv("PATH"))
  55. env_base.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
  56. if "TERM" in os.environ: # Used for colored output.
  57. env_base["ENV"]["TERM"] = os.environ["TERM"]
  58. env_base.disabled_modules = []
  59. env_base.module_version_string = ""
  60. env_base.msvc = False
  61. env_base.__class__.disable_module = methods.disable_module
  62. env_base.__class__.add_module_version_string = methods.add_module_version_string
  63. env_base.__class__.add_source_files = methods.add_source_files
  64. env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix
  65. env_base.__class__.add_shared_library = methods.add_shared_library
  66. env_base.__class__.add_library = methods.add_library
  67. env_base.__class__.add_program = methods.add_program
  68. env_base.__class__.CommandNoCache = methods.CommandNoCache
  69. env_base.__class__.Run = methods.Run
  70. env_base.__class__.disable_warnings = methods.disable_warnings
  71. env_base.__class__.module_check_dependencies = methods.module_check_dependencies
  72. env_base["x86_libtheora_opt_gcc"] = False
  73. env_base["x86_libtheora_opt_vc"] = False
  74. # avoid issues when building with different versions of python out of the same directory
  75. env_base.SConsignFile(".sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL))
  76. # Build options
  77. customs = ["custom.py"]
  78. profile = ARGUMENTS.get("profile", "")
  79. if profile:
  80. if os.path.isfile(profile):
  81. customs.append(profile)
  82. elif os.path.isfile(profile + ".py"):
  83. customs.append(profile + ".py")
  84. opts = Variables(customs, ARGUMENTS)
  85. # Target build options
  86. opts.Add("p", "Platform (alias for 'platform')", "")
  87. opts.Add("platform", "Target platform (%s)" % ("|".join(platform_list),), "")
  88. opts.Add(BoolVariable("tools", "Build the tools (a.k.a. the Godot editor)", True))
  89. opts.Add(EnumVariable("target", "Compilation target", "debug", ("debug", "release_debug", "release")))
  90. opts.Add("arch", "Platform-dependent architecture (arm/arm64/x86/x64/mips/...)", "")
  91. opts.Add(EnumVariable("bits", "Target platform bits", "default", ("default", "32", "64")))
  92. opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size", "none")))
  93. opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
  94. opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
  95. # Components
  96. opts.Add(BoolVariable("deprecated", "Enable deprecated features", True))
  97. opts.Add(BoolVariable("minizip", "Enable ZIP archive support using minizip", True))
  98. opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver", False))
  99. opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
  100. opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
  101. # Advanced options
  102. opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False))
  103. opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True))
  104. opts.Add(BoolVariable("tests", "Build the unit tests", False))
  105. opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
  106. opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no")))
  107. opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", False))
  108. opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "")
  109. opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False))
  110. opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable", False))
  111. opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False))
  112. opts.Add(BoolVariable("modules_enabled_by_default", "If no, disable all modules except ones explicitly enabled", True))
  113. opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", False))
  114. opts.Add("system_certs_path", "Use this path as SSL certificates default for editor (for package maintainers)", "")
  115. opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False))
  116. # Thirdparty libraries
  117. opts.Add(BoolVariable("builtin_bullet", "Use the built-in Bullet library", True))
  118. opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True))
  119. opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
  120. opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True))
  121. opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True))
  122. opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
  123. opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
  124. opts.Add(BoolVariable("builtin_icu", "Use the built-in ICU library", True))
  125. opts.Add(BoolVariable("builtin_libogg", "Use the built-in libogg library", True))
  126. opts.Add(BoolVariable("builtin_libpng", "Use the built-in libpng library", True))
  127. opts.Add(BoolVariable("builtin_libtheora", "Use the built-in libtheora library", True))
  128. opts.Add(BoolVariable("builtin_libvorbis", "Use the built-in libvorbis library", True))
  129. opts.Add(BoolVariable("builtin_libvpx", "Use the built-in libvpx library", True))
  130. opts.Add(BoolVariable("builtin_libwebp", "Use the built-in libwebp library", True))
  131. opts.Add(BoolVariable("builtin_wslay", "Use the built-in wslay library", True))
  132. opts.Add(BoolVariable("builtin_mbedtls", "Use the built-in mbedTLS library", True))
  133. opts.Add(BoolVariable("builtin_miniupnpc", "Use the built-in miniupnpc library", True))
  134. opts.Add(BoolVariable("builtin_opus", "Use the built-in Opus library", True))
  135. opts.Add(BoolVariable("builtin_pcre2", "Use the built-in PCRE2 library", True))
  136. opts.Add(BoolVariable("builtin_pcre2_with_jit", "Use JIT compiler for the built-in PCRE2 library", True))
  137. opts.Add(BoolVariable("builtin_recast", "Use the built-in Recast library", True))
  138. opts.Add(BoolVariable("builtin_rvo2", "Use the built-in RVO2 library", True))
  139. opts.Add(BoolVariable("builtin_squish", "Use the built-in squish library", True))
  140. opts.Add(BoolVariable("builtin_vulkan", "Use the built-in Vulkan loader library and headers", True))
  141. opts.Add(BoolVariable("builtin_xatlas", "Use the built-in xatlas library", True))
  142. opts.Add(BoolVariable("builtin_zlib", "Use the built-in zlib library", True))
  143. opts.Add(BoolVariable("builtin_zstd", "Use the built-in Zstd library", True))
  144. # Compilation environment setup
  145. opts.Add("CXX", "C++ compiler")
  146. opts.Add("CC", "C compiler")
  147. opts.Add("LINK", "Linker")
  148. opts.Add("CCFLAGS", "Custom flags for both the C and C++ compilers")
  149. opts.Add("CFLAGS", "Custom flags for the C compiler")
  150. opts.Add("CXXFLAGS", "Custom flags for the C++ compiler")
  151. opts.Add("LINKFLAGS", "Custom flags for the linker")
  152. # Update the environment to have all above options defined
  153. # in following code (especially platform and custom_modules).
  154. opts.Update(env_base)
  155. # Platform selection: validate input, and add options.
  156. selected_platform = ""
  157. if env_base["platform"] != "":
  158. selected_platform = env_base["platform"]
  159. elif env_base["p"] != "":
  160. selected_platform = env_base["p"]
  161. else:
  162. # Missing `platform` argument, try to detect platform automatically
  163. if sys.platform.startswith("linux"):
  164. selected_platform = "linuxbsd"
  165. elif sys.platform == "darwin":
  166. selected_platform = "osx"
  167. elif sys.platform == "win32":
  168. selected_platform = "windows"
  169. else:
  170. print("Could not detect platform automatically. Supported platforms:")
  171. for x in platform_list:
  172. print("\t" + x)
  173. print("\nPlease run SCons again and select a valid platform: platform=<string>")
  174. if selected_platform != "":
  175. print("Automatically detected platform: " + selected_platform)
  176. if selected_platform in ["linux", "bsd", "x11"]:
  177. if selected_platform == "x11":
  178. # Deprecated alias kept for compatibility.
  179. print('Platform "x11" has been renamed to "linuxbsd" in Godot 4.0. Building for platform "linuxbsd".')
  180. # Alias for convenience.
  181. selected_platform = "linuxbsd"
  182. # Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference.
  183. # It should always be re-set after calling `opts.Update()` otherwise it uses the original input value.
  184. env_base["platform"] = selected_platform
  185. # Add platform-specific options.
  186. if selected_platform in platform_opts:
  187. for opt in platform_opts[selected_platform]:
  188. opts.Add(opt)
  189. # Update the environment to take platform-specific options into account.
  190. opts.Update(env_base)
  191. env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
  192. # Detect modules.
  193. modules_detected = OrderedDict()
  194. module_search_paths = ["modules"] # Built-in path.
  195. if env_base["custom_modules"]:
  196. paths = env_base["custom_modules"].split(",")
  197. for p in paths:
  198. try:
  199. module_search_paths.append(methods.convert_custom_modules_path(p))
  200. except ValueError as e:
  201. print(e)
  202. Exit(255)
  203. for path in module_search_paths:
  204. if path == "modules":
  205. # Built-in modules don't have nested modules,
  206. # so save the time it takes to parse directories.
  207. modules = methods.detect_modules(path, recursive=False)
  208. else: # Custom.
  209. modules = methods.detect_modules(path, env_base["custom_modules_recursive"])
  210. # Provide default include path for both the custom module search `path`
  211. # and the base directory containing custom modules, as it may be different
  212. # from the built-in "modules" name (e.g. "custom_modules/summator/summator.h"),
  213. # so it can be referenced simply as `#include "summator/summator.h"`
  214. # independently of where a module is located on user's filesystem.
  215. env_base.Prepend(CPPPATH=[path, os.path.dirname(path)])
  216. # Note: custom modules can override built-in ones.
  217. modules_detected.update(modules)
  218. # Add module options.
  219. for name, path in modules_detected.items():
  220. if env_base["modules_enabled_by_default"]:
  221. enabled = True
  222. sys.path.insert(0, path)
  223. import config
  224. try:
  225. enabled = config.is_enabled()
  226. except AttributeError:
  227. pass
  228. sys.path.remove(path)
  229. sys.modules.pop("config")
  230. else:
  231. enabled = False
  232. opts.Add(BoolVariable("module_" + name + "_enabled", "Enable module '%s'" % (name,), enabled))
  233. methods.write_modules(modules_detected)
  234. # Update the environment again after all the module options are added.
  235. opts.Update(env_base)
  236. env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
  237. Help(opts.GenerateHelpText(env_base))
  238. # add default include paths
  239. env_base.Prepend(CPPPATH=["#"])
  240. # configure ENV for platform
  241. env_base.platform_exporters = platform_exporters
  242. env_base.platform_apis = platform_apis
  243. if env_base["use_precise_math_checks"]:
  244. env_base.Append(CPPDEFINES=["PRECISE_MATH_CHECKS"])
  245. if env_base["target"] == "debug":
  246. env_base.Append(CPPDEFINES=["DEBUG_MEMORY_ALLOC", "DISABLE_FORCED_INLINE"])
  247. # The two options below speed up incremental builds, but reduce the certainty that all files
  248. # will properly be rebuilt. As such, we only enable them for debug (dev) builds, not release.
  249. # To decide whether to rebuild a file, use the MD5 sum only if the timestamp has changed.
  250. # http://scons.org/doc/production/HTML/scons-user/ch06.html#idm139837621851792
  251. env_base.Decider("MD5-timestamp")
  252. # Use cached implicit dependencies by default. Can be overridden by specifying `--implicit-deps-changed` in the command line.
  253. # http://scons.org/doc/production/HTML/scons-user/ch06s04.html
  254. env_base.SetOption("implicit_cache", 1)
  255. if env_base["no_editor_splash"]:
  256. env_base.Append(CPPDEFINES=["NO_EDITOR_SPLASH"])
  257. if not env_base["deprecated"]:
  258. env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"])
  259. if selected_platform in platform_list:
  260. tmppath = "./platform/" + selected_platform
  261. sys.path.insert(0, tmppath)
  262. import detect
  263. if "create" in dir(detect):
  264. env = detect.create(env_base)
  265. else:
  266. env = env_base.Clone()
  267. # Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later.
  268. from SCons import __version__ as scons_raw_version
  269. scons_ver = env._get_major_minor_revision(scons_raw_version)
  270. if scons_ver >= (4, 0, 0):
  271. env.Tool("compilation_db")
  272. env.Alias("compiledb", env.CompilationDatabase())
  273. # 'dev' and 'production' are aliases to set default options if they haven't been set
  274. # manually by the user.
  275. if env["dev"]:
  276. env["verbose"] = methods.get_cmdline_bool("verbose", True)
  277. env["warnings"] = ARGUMENTS.get("warnings", "extra")
  278. env["werror"] = methods.get_cmdline_bool("werror", True)
  279. if env["tools"]:
  280. env["tests"] = methods.get_cmdline_bool("tests", True)
  281. if env["production"]:
  282. env["use_static_cpp"] = methods.get_cmdline_bool("use_static_cpp", True)
  283. env["use_lto"] = methods.get_cmdline_bool("use_lto", True)
  284. env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)
  285. if not env["tools"] and env["target"] == "debug":
  286. print(
  287. "WARNING: Requested `production` build with `tools=no target=debug`, "
  288. "this will give you a full debug template (use `target=release_debug` "
  289. "for an optimized template with debug features)."
  290. )
  291. if env.msvc:
  292. print(
  293. "WARNING: For `production` Windows builds, you should use MinGW with GCC "
  294. "or Clang instead of Visual Studio, as they can better optimize the "
  295. "GDScript VM in a very significant way. MSVC LTO also doesn't work "
  296. "reliably for our use case."
  297. "If you want to use MSVC nevertheless for production builds, set "
  298. "`debug_symbols=no use_lto=no` instead of the `production=yes` option."
  299. )
  300. Exit(255)
  301. env.extra_suffix = ""
  302. if env["extra_suffix"] != "":
  303. env.extra_suffix += "." + env["extra_suffix"]
  304. # Environment flags
  305. CCFLAGS = env.get("CCFLAGS", "")
  306. env["CCFLAGS"] = ""
  307. env.Append(CCFLAGS=str(CCFLAGS).split())
  308. CFLAGS = env.get("CFLAGS", "")
  309. env["CFLAGS"] = ""
  310. env.Append(CFLAGS=str(CFLAGS).split())
  311. CXXFLAGS = env.get("CXXFLAGS", "")
  312. env["CXXFLAGS"] = ""
  313. env.Append(CXXFLAGS=str(CXXFLAGS).split())
  314. LINKFLAGS = env.get("LINKFLAGS", "")
  315. env["LINKFLAGS"] = ""
  316. env.Append(LINKFLAGS=str(LINKFLAGS).split())
  317. # Platform specific flags
  318. flag_list = platform_flags[selected_platform]
  319. for f in flag_list:
  320. if not (f[0] in ARGUMENTS): # allow command line to override platform flags
  321. env[f[0]] = f[1]
  322. # Must happen after the flags' definition, so that they can be used by platform detect
  323. detect.configure(env)
  324. # Set our C and C++ standard requirements.
  325. # C++17 is required as we need guaranteed copy elision as per GH-36436.
  326. # Prepending to make it possible to override.
  327. # This needs to come after `configure`, otherwise we don't have env.msvc.
  328. if not env.msvc:
  329. # Specifying GNU extensions support explicitly, which are supported by
  330. # both GCC and Clang. Both currently default to gnu11 and gnu++14.
  331. env.Prepend(CFLAGS=["-std=gnu11"])
  332. env.Prepend(CXXFLAGS=["-std=gnu++17"])
  333. else:
  334. # MSVC doesn't have clear C standard support, /std only covers C++.
  335. # We apply it to CCFLAGS (both C and C++ code) in case it impacts C features.
  336. env.Prepend(CCFLAGS=["/std:c++17"])
  337. # Enforce our minimal compiler version requirements
  338. cc_version = methods.get_compiler_version(env) or [-1, -1]
  339. cc_version_major = cc_version[0]
  340. cc_version_minor = cc_version[1]
  341. if methods.using_gcc(env):
  342. # GCC 8 before 8.4 has a regression in the support of guaranteed copy elision
  343. # which causes a build failure: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521
  344. if cc_version_major == 8 and cc_version_minor < 4:
  345. print(
  346. "Detected GCC 8 version < 8.4, which is not supported due to a "
  347. "regression in its C++17 guaranteed copy elision support. Use a "
  348. 'newer GCC version, or Clang 6 or later by passing "use_llvm=yes" '
  349. "to the SCons command line."
  350. )
  351. Exit(255)
  352. elif cc_version_major < 7:
  353. print(
  354. "Detected GCC version older than 7, which does not fully support "
  355. "C++17. Supported versions are GCC 7, 9 and later. Use a newer GCC "
  356. 'version, or Clang 6 or later by passing "use_llvm=yes" to the '
  357. "SCons command line."
  358. )
  359. Exit(255)
  360. elif methods.using_clang(env):
  361. # Apple LLVM versions differ from upstream LLVM version \o/, compare
  362. # in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
  363. if env["platform"] == "osx" or env["platform"] == "iphone":
  364. vanilla = methods.is_vanilla_clang(env)
  365. if vanilla and cc_version_major < 6:
  366. print(
  367. "Detected Clang version older than 6, which does not fully support "
  368. "C++17. Supported versions are Clang 6 and later."
  369. )
  370. Exit(255)
  371. elif not vanilla and cc_version_major < 10:
  372. print(
  373. "Detected Apple Clang version older than 10, which does not fully "
  374. "support C++17. Supported versions are Apple Clang 10 and later."
  375. )
  376. Exit(255)
  377. elif cc_version_major < 6:
  378. print(
  379. "Detected Clang version older than 6, which does not fully support "
  380. "C++17. Supported versions are Clang 6 and later."
  381. )
  382. Exit(255)
  383. # Configure compiler warnings
  384. if env.msvc: # MSVC
  385. # Truncations, narrowing conversions, signed/unsigned comparisons...
  386. disable_nonessential_warnings = ["/wd4267", "/wd4244", "/wd4305", "/wd4018", "/wd4800"]
  387. if env["warnings"] == "extra":
  388. env.Append(CCFLAGS=["/Wall"]) # Implies /W4
  389. elif env["warnings"] == "all":
  390. env.Append(CCFLAGS=["/W3"] + disable_nonessential_warnings)
  391. elif env["warnings"] == "moderate":
  392. env.Append(CCFLAGS=["/W2"] + disable_nonessential_warnings)
  393. else: # 'no'
  394. env.Append(CCFLAGS=["/w"])
  395. # Set exception handling model to avoid warnings caused by Windows system headers.
  396. env.Append(CCFLAGS=["/EHsc"])
  397. if env["werror"]:
  398. env.Append(CCFLAGS=["/WX"])
  399. else: # GCC, Clang
  400. gcc_common_warnings = []
  401. if methods.using_gcc(env):
  402. gcc_common_warnings += ["-Wshadow-local", "-Wno-misleading-indentation"]
  403. if env["warnings"] == "extra":
  404. env.Append(CCFLAGS=["-Wall", "-Wextra", "-Wwrite-strings", "-Wno-unused-parameter"] + gcc_common_warnings)
  405. env.Append(CXXFLAGS=["-Wctor-dtor-privacy", "-Wnon-virtual-dtor"])
  406. if methods.using_gcc(env):
  407. env.Append(
  408. CCFLAGS=[
  409. "-Walloc-zero",
  410. "-Wduplicated-branches",
  411. "-Wduplicated-cond",
  412. "-Wstringop-overflow=4",
  413. "-Wlogical-op",
  414. ]
  415. )
  416. # -Wnoexcept was removed temporarily due to GH-36325.
  417. env.Append(CXXFLAGS=["-Wplacement-new=1"])
  418. if cc_version_major >= 9:
  419. env.Append(CCFLAGS=["-Wattribute-alias=2"])
  420. elif methods.using_clang(env):
  421. env.Append(CCFLAGS=["-Wimplicit-fallthrough"])
  422. elif env["warnings"] == "all":
  423. env.Append(CCFLAGS=["-Wall"] + gcc_common_warnings)
  424. elif env["warnings"] == "moderate":
  425. env.Append(CCFLAGS=["-Wall", "-Wno-unused"] + gcc_common_warnings)
  426. else: # 'no'
  427. env.Append(CCFLAGS=["-w"])
  428. if env["werror"]:
  429. env.Append(CCFLAGS=["-Werror"])
  430. # FIXME: Temporary workaround after the Vulkan merge, remove once warnings are fixed.
  431. if methods.using_gcc(env):
  432. env.Append(CXXFLAGS=["-Wno-error=cpp"])
  433. if cc_version_major == 7: # Bogus warning fixed in 8+.
  434. env.Append(CCFLAGS=["-Wno-error=strict-overflow"])
  435. else:
  436. env.Append(CXXFLAGS=["-Wno-error=#warnings"])
  437. else: # always enable those errors
  438. env.Append(CCFLAGS=["-Werror=return-type"])
  439. if hasattr(detect, "get_program_suffix"):
  440. suffix = "." + detect.get_program_suffix()
  441. else:
  442. suffix = "." + selected_platform
  443. if env["target"] == "release":
  444. if env["tools"]:
  445. print("Tools can only be built with targets 'debug' and 'release_debug'.")
  446. Exit(255)
  447. suffix += ".opt"
  448. env.Append(CPPDEFINES=["NDEBUG"])
  449. elif env["target"] == "release_debug":
  450. if env["tools"]:
  451. suffix += ".opt.tools"
  452. else:
  453. suffix += ".opt.debug"
  454. else:
  455. if env["tools"]:
  456. suffix += ".tools"
  457. else:
  458. suffix += ".debug"
  459. if env["arch"] != "":
  460. suffix += "." + env["arch"]
  461. elif env["bits"] == "32":
  462. suffix += ".32"
  463. elif env["bits"] == "64":
  464. suffix += ".64"
  465. suffix += env.extra_suffix
  466. sys.path.remove(tmppath)
  467. sys.modules.pop("detect")
  468. modules_enabled = OrderedDict()
  469. env.module_icons_paths = []
  470. env.doc_class_path = {}
  471. for name, path in modules_detected.items():
  472. if not env["module_" + name + "_enabled"]:
  473. continue
  474. sys.path.insert(0, path)
  475. env.current_module = name
  476. import config
  477. if config.can_build(env, selected_platform):
  478. config.configure(env)
  479. # Get doc classes paths (if present)
  480. try:
  481. doc_classes = config.get_doc_classes()
  482. doc_path = config.get_doc_path()
  483. for c in doc_classes:
  484. env.doc_class_path[c] = path + "/" + doc_path
  485. except Exception:
  486. pass
  487. # Get icon paths (if present)
  488. try:
  489. icons_path = config.get_icons_path()
  490. env.module_icons_paths.append(path + "/" + icons_path)
  491. except Exception:
  492. # Default path for module icons
  493. env.module_icons_paths.append(path + "/" + "icons")
  494. modules_enabled[name] = path
  495. sys.path.remove(path)
  496. sys.modules.pop("config")
  497. env.module_list = modules_enabled
  498. methods.update_version(env.module_version_string)
  499. env["PROGSUFFIX"] = suffix + env.module_version_string + env["PROGSUFFIX"]
  500. env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
  501. # (SH)LIBSUFFIX will be used for our own built libraries
  502. # LIBSUFFIXES contains LIBSUFFIX and SHLIBSUFFIX by default,
  503. # so we need to append the default suffixes to keep the ability
  504. # to link against thirdparty libraries (.a, .so, .lib, etc.).
  505. if os.name == "nt":
  506. # On Windows, only static libraries and import libraries can be
  507. # statically linked - both using .lib extension
  508. env["LIBSUFFIXES"] += [env["LIBSUFFIX"]]
  509. else:
  510. env["LIBSUFFIXES"] += [env["LIBSUFFIX"], env["SHLIBSUFFIX"]]
  511. env["LIBSUFFIX"] = suffix + env["LIBSUFFIX"]
  512. env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"]
  513. if env["tools"]:
  514. env.Append(CPPDEFINES=["TOOLS_ENABLED"])
  515. if env["disable_3d"]:
  516. if env["tools"]:
  517. print(
  518. "Build option 'disable_3d=yes' cannot be used with 'tools=yes' (editor), "
  519. "only with 'tools=no' (export template)."
  520. )
  521. Exit(255)
  522. else:
  523. env.Append(CPPDEFINES=["_3D_DISABLED"])
  524. if env["disable_advanced_gui"]:
  525. if env["tools"]:
  526. print(
  527. "Build option 'disable_advanced_gui=yes' cannot be used with 'tools=yes' (editor), "
  528. "only with 'tools=no' (export template)."
  529. )
  530. Exit(255)
  531. else:
  532. env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"])
  533. if env["minizip"]:
  534. env.Append(CPPDEFINES=["MINIZIP_ENABLED"])
  535. editor_module_list = ["freetype", "regex"]
  536. if env["tools"] and not env.module_check_dependencies("tools", editor_module_list):
  537. print(
  538. "Build option 'module_"
  539. + x
  540. + "_enabled=no' cannot be used with 'tools=yes' (editor), only with 'tools=no' (export template)."
  541. )
  542. Exit(255)
  543. if not env["verbose"]:
  544. methods.no_verbose(sys, env)
  545. if not env["platform"] == "server":
  546. GLSL_BUILDERS = {
  547. "RD_GLSL": env.Builder(
  548. action=env.Run(glsl_builders.build_rd_headers, 'Building RD_GLSL header: "$TARGET"'),
  549. suffix="glsl.gen.h",
  550. src_suffix=".glsl",
  551. ),
  552. "GLSL_HEADER": env.Builder(
  553. action=env.Run(glsl_builders.build_raw_headers, 'Building GLSL header: "$TARGET"'),
  554. suffix="glsl.gen.h",
  555. src_suffix=".glsl",
  556. ),
  557. }
  558. env.Append(BUILDERS=GLSL_BUILDERS)
  559. scons_cache_path = os.environ.get("SCONS_CACHE")
  560. if scons_cache_path != None:
  561. CacheDir(scons_cache_path)
  562. print("Scons cache enabled... (path: '" + scons_cache_path + "')")
  563. if env["vsproj"]:
  564. env.vs_incs = []
  565. env.vs_srcs = []
  566. Export("env")
  567. # Build subdirs, the build order is dependent on link order.
  568. SConscript("core/SCsub")
  569. SConscript("servers/SCsub")
  570. SConscript("scene/SCsub")
  571. SConscript("editor/SCsub")
  572. SConscript("drivers/SCsub")
  573. SConscript("platform/SCsub")
  574. SConscript("modules/SCsub")
  575. if env["tests"]:
  576. SConscript("tests/SCsub")
  577. SConscript("main/SCsub")
  578. SConscript("platform/" + selected_platform + "/SCsub") # Build selected platform.
  579. # Microsoft Visual Studio Project Generation
  580. if env["vsproj"]:
  581. env["CPPPATH"] = [Dir(path) for path in env["CPPPATH"]]
  582. methods.generate_vs_project(env, GetOption("num_jobs"))
  583. methods.generate_cpp_hint_file("cpp.hint")
  584. # Check for the existence of headers
  585. conf = Configure(env)
  586. if "check_c_headers" in env:
  587. for header in env["check_c_headers"]:
  588. if conf.CheckCHeader(header[0]):
  589. env.AppendUnique(CPPDEFINES=[header[1]])
  590. elif selected_platform != "":
  591. if selected_platform == "list":
  592. print("The following platforms are available:\n")
  593. else:
  594. print('Invalid target platform "' + selected_platform + '".')
  595. print("The following platforms were detected:\n")
  596. for x in platform_list:
  597. print("\t" + x)
  598. print("\nPlease run SCons again and select a valid platform: platform=<string>")
  599. if selected_platform == "list":
  600. # Exit early to suppress the rest of the built-in SCons messages
  601. Exit()
  602. else:
  603. Exit(255)
  604. # The following only makes sense when the 'env' is defined, and assumes it is.
  605. if "env" in locals():
  606. methods.show_progress(env)
  607. # TODO: replace this with `env.Dump(format="json")`
  608. # once we start requiring SCons 4.0 as min version.
  609. methods.dump(env)