SConstruct 28 KB

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