SConstruct 27 KB

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