SCsub 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. import os
  4. import core_builders
  5. import methods
  6. Import("env")
  7. env.core_sources = []
  8. # Add required thirdparty code.
  9. thirdparty_obj = []
  10. env_thirdparty = env.Clone()
  11. env_thirdparty.disable_warnings()
  12. # Misc thirdparty code: header paths are hardcoded, we don't need to append
  13. # to the include path (saves a few chars on the compiler invocation for touchy MSVC...)
  14. thirdparty_misc_dir = "#thirdparty/misc/"
  15. thirdparty_misc_sources = [
  16. # C sources
  17. "fastlz.c",
  18. "r128.c",
  19. "smaz.c",
  20. # C++ sources
  21. "pcg.cpp",
  22. "polypartition.cpp",
  23. "smolv.cpp",
  24. ]
  25. thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
  26. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_misc_sources)
  27. # Brotli
  28. if env["brotli"] and env["builtin_brotli"]:
  29. thirdparty_brotli_dir = "#thirdparty/brotli/"
  30. thirdparty_brotli_sources = [
  31. "common/constants.c",
  32. "common/context.c",
  33. "common/dictionary.c",
  34. "common/platform.c",
  35. "common/shared_dictionary.c",
  36. "common/transform.c",
  37. "dec/bit_reader.c",
  38. "dec/decode.c",
  39. "dec/huffman.c",
  40. "dec/prefix.c",
  41. "dec/state.c",
  42. "dec/static_init.c",
  43. ]
  44. thirdparty_brotli_sources = [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources]
  45. env_thirdparty.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
  46. env.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
  47. if env.get("use_ubsan") or env.get("use_asan") or env.get("use_tsan") or env.get("use_lsan") or env.get("use_msan"):
  48. env_thirdparty.Append(CPPDEFINES=["BROTLI_BUILD_PORTABLE"])
  49. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_brotli_sources)
  50. # Clipper2 Thirdparty source files used for polygon and polyline boolean operations.
  51. if env["builtin_clipper2"]:
  52. thirdparty_clipper_dir = "#thirdparty/clipper2/"
  53. thirdparty_clipper_sources = [
  54. "src/clipper.engine.cpp",
  55. "src/clipper.offset.cpp",
  56. "src/clipper.rectclip.cpp",
  57. ]
  58. thirdparty_clipper_sources = [thirdparty_clipper_dir + file for file in thirdparty_clipper_sources]
  59. env_thirdparty.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"])
  60. env.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"])
  61. env_thirdparty.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  62. env.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  63. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_clipper_sources)
  64. # Zlib library, can be unbundled
  65. if env["builtin_zlib"]:
  66. thirdparty_zlib_dir = "#thirdparty/zlib/"
  67. thirdparty_zlib_sources = [
  68. "adler32.c",
  69. "compress.c",
  70. "crc32.c",
  71. "deflate.c",
  72. "inffast.c",
  73. "inflate.c",
  74. "inftrees.c",
  75. "trees.c",
  76. "uncompr.c",
  77. "zutil.c",
  78. ]
  79. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  80. env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
  81. # Needs to be available in main env too
  82. env.Prepend(CPPPATH=[thirdparty_zlib_dir])
  83. if env.dev_build:
  84. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  85. # Affects headers so it should also be defined for Godot code
  86. env.Append(CPPDEFINES=["ZLIB_DEBUG"])
  87. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
  88. # Minizip library, could be unbundled in theory
  89. # However, our version has some custom modifications, so it won't compile with the system one
  90. thirdparty_minizip_dir = "#thirdparty/minizip/"
  91. thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
  92. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  93. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
  94. # Zstd library, can be unbundled
  95. if env["builtin_zstd"]:
  96. thirdparty_zstd_dir = "#thirdparty/zstd/"
  97. thirdparty_zstd_sources = [
  98. "common/debug.c",
  99. "common/entropy_common.c",
  100. "common/error_private.c",
  101. "common/fse_decompress.c",
  102. "common/pool.c",
  103. "common/threading.c",
  104. "common/xxhash.c",
  105. "common/zstd_common.c",
  106. "compress/fse_compress.c",
  107. "compress/hist.c",
  108. "compress/huf_compress.c",
  109. "compress/zstd_compress.c",
  110. "compress/zstd_double_fast.c",
  111. "compress/zstd_fast.c",
  112. "compress/zstd_lazy.c",
  113. "compress/zstd_ldm.c",
  114. "compress/zstd_opt.c",
  115. "compress/zstd_preSplit.c",
  116. "compress/zstdmt_compress.c",
  117. "compress/zstd_compress_literals.c",
  118. "compress/zstd_compress_sequences.c",
  119. "compress/zstd_compress_superblock.c",
  120. "decompress/huf_decompress.c",
  121. "decompress/zstd_ddict.c",
  122. "decompress/zstd_decompress_block.c",
  123. "decompress/zstd_decompress.c",
  124. ]
  125. if (
  126. env["platform"] in ["android", "ios", "linuxbsd", "macos", "windows"]
  127. and env["arch"] == "x86_64"
  128. and not env.msvc
  129. ):
  130. # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
  131. thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
  132. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  133. env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  134. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  135. env.Prepend(CPPPATH=thirdparty_zstd_dir)
  136. # Also needed in main env includes will trigger warnings
  137. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  138. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
  139. env.core_sources += thirdparty_obj
  140. # Godot source files
  141. env.add_source_files(env.core_sources, "*.cpp")
  142. # Generate disabled classes
  143. env.CommandNoCache(
  144. "disabled_classes.gen.h", env.Value(env.disabled_classes), env.Run(core_builders.disabled_class_builder)
  145. )
  146. # Generate version info
  147. env.CommandNoCache(
  148. "version_generated.gen.h",
  149. env.Value(methods.get_version_info(env.module_version_string)),
  150. env.Run(core_builders.version_info_builder),
  151. )
  152. # Generate version hash
  153. gen_hash = env.CommandNoCache(
  154. "version_hash.gen.cpp", env.Value(methods.get_git_info()), env.Run(core_builders.version_hash_builder)
  155. )
  156. env.add_source_files(env.core_sources, gen_hash)
  157. # Generate AES256 script encryption key
  158. encryption_key = os.environ.get("SCRIPT_AES256_ENCRYPTION_KEY")
  159. if encryption_key:
  160. print(
  161. "\n*** IMPORTANT: Compiling Godot with custom `SCRIPT_AES256_ENCRYPTION_KEY` set as environment variable."
  162. "\n*** Make sure to use templates compiled with this key when exporting a project with encryption.\n"
  163. )
  164. gen_encrypt = env.CommandNoCache(
  165. "script_encryption_key.gen.cpp",
  166. env.Value(encryption_key),
  167. env.Run(core_builders.encryption_key_builder),
  168. )
  169. env.add_source_files(env.core_sources, gen_encrypt)
  170. # Certificates
  171. env.CommandNoCache(
  172. "#core/io/certs_compressed.gen.h",
  173. ["#thirdparty/certs/ca-bundle.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  174. env.Run(core_builders.make_certs_header),
  175. )
  176. # Authors
  177. env.CommandNoCache("#core/authors.gen.h", "#AUTHORS.md", env.Run(core_builders.make_authors_header))
  178. # Donors
  179. env.CommandNoCache("#core/donors.gen.h", "#DONORS.md", env.Run(core_builders.make_donors_header))
  180. # License
  181. env.CommandNoCache(
  182. "#core/license.gen.h", ["#COPYRIGHT.txt", "#LICENSE.txt"], env.Run(core_builders.make_license_header)
  183. )
  184. # Chain load SCsubs
  185. SConscript("profiling/SCsub")
  186. SConscript("os/SCsub")
  187. SConscript("math/SCsub")
  188. SConscript("crypto/SCsub")
  189. SConscript("io/SCsub")
  190. SConscript("debugger/SCsub")
  191. SConscript("input/SCsub")
  192. SConscript("variant/SCsub")
  193. SConscript("extension/SCsub")
  194. SConscript("object/SCsub")
  195. SConscript("templates/SCsub")
  196. SConscript("string/SCsub")
  197. SConscript("config/SCsub")
  198. SConscript("error/SCsub")
  199. # Build it all as a library
  200. lib = env.add_library("core", env.core_sources)
  201. env.Prepend(LIBS=[lib])
  202. # Needed to force rebuilding the core files when the thirdparty code is updated.
  203. env.Depends(lib, thirdparty_obj)