SConstruct 25 KB

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