SCsub 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/state.c",
  41. ]
  42. thirdparty_brotli_sources = [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources]
  43. env_thirdparty.Prepend(CPPEXTPATH=[thirdparty_brotli_dir + "include"])
  44. env.Prepend(CPPEXTPATH=[thirdparty_brotli_dir + "include"])
  45. 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"):
  46. env_thirdparty.Append(CPPDEFINES=["BROTLI_BUILD_PORTABLE"])
  47. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_brotli_sources)
  48. # Clipper2 Thirdparty source files used for polygon and polyline boolean operations.
  49. if env["builtin_clipper2"]:
  50. thirdparty_clipper_dir = "#thirdparty/clipper2/"
  51. thirdparty_clipper_sources = [
  52. "src/clipper.engine.cpp",
  53. "src/clipper.offset.cpp",
  54. "src/clipper.rectclip.cpp",
  55. ]
  56. thirdparty_clipper_sources = [thirdparty_clipper_dir + file for file in thirdparty_clipper_sources]
  57. env_thirdparty.Prepend(CPPEXTPATH=[thirdparty_clipper_dir + "include"])
  58. env.Prepend(CPPEXTPATH=[thirdparty_clipper_dir + "include"])
  59. env_thirdparty.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  60. env.Append(CPPDEFINES=["CLIPPER2_ENABLED"])
  61. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_clipper_sources)
  62. # Zlib library, can be unbundled
  63. if env["builtin_zlib"]:
  64. thirdparty_zlib_dir = "#thirdparty/zlib/"
  65. thirdparty_zlib_sources = [
  66. "adler32.c",
  67. "compress.c",
  68. "crc32.c",
  69. "deflate.c",
  70. "inffast.c",
  71. "inflate.c",
  72. "inftrees.c",
  73. "trees.c",
  74. "uncompr.c",
  75. "zutil.c",
  76. ]
  77. thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
  78. env_thirdparty.Prepend(CPPEXTPATH=[thirdparty_zlib_dir])
  79. # Needs to be available in main env too
  80. env.Prepend(CPPEXTPATH=[thirdparty_zlib_dir])
  81. if env.dev_build:
  82. env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
  83. # Affects headers so it should also be defined for Godot code
  84. env.Append(CPPDEFINES=["ZLIB_DEBUG"])
  85. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
  86. # Minizip library, could be unbundled in theory
  87. # However, our version has some custom modifications, so it won't compile with the system one
  88. thirdparty_minizip_dir = "#thirdparty/minizip/"
  89. thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
  90. thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
  91. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
  92. # Zstd library, can be unbundled in theory
  93. # though we currently use some private symbols
  94. # https://github.com/godotengine/godot/issues/17374
  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/zstdmt_compress.c",
  116. "compress/zstd_compress_literals.c",
  117. "compress/zstd_compress_sequences.c",
  118. "compress/zstd_compress_superblock.c",
  119. "decompress/huf_decompress.c",
  120. "decompress/zstd_ddict.c",
  121. "decompress/zstd_decompress_block.c",
  122. "decompress/zstd_decompress.c",
  123. ]
  124. if env["platform"] in ["android", "ios", "linuxbsd", "macos"] and env["arch"] == "x86_64":
  125. # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
  126. thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
  127. thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
  128. env_thirdparty.Prepend(CPPEXTPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
  129. env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  130. env.Prepend(CPPEXTPATH=thirdparty_zstd_dir)
  131. # Also needed in main env includes will trigger warnings
  132. env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
  133. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
  134. env.core_sources += thirdparty_obj
  135. # Godot source files
  136. env.add_source_files(env.core_sources, "*.cpp")
  137. # Generate disabled classes
  138. env.CommandNoCache(
  139. "disabled_classes.gen.h", env.Value(env.disabled_classes), env.Run(core_builders.disabled_class_builder)
  140. )
  141. # Generate version info
  142. env.CommandNoCache(
  143. "version_generated.gen.h",
  144. env.Value(methods.get_version_info(env.module_version_string)),
  145. env.Run(core_builders.version_info_builder),
  146. )
  147. # Generate version hash
  148. gen_hash = env.CommandNoCache(
  149. "version_hash.gen.cpp", env.Value(methods.get_git_info()), env.Run(core_builders.version_hash_builder)
  150. )
  151. env.add_source_files(env.core_sources, gen_hash)
  152. # Generate AES256 script encryption key
  153. gen_encrypt = env.CommandNoCache(
  154. "script_encryption_key.gen.cpp",
  155. env.Value(os.environ.get("SCRIPT_AES256_ENCRYPTION_KEY")),
  156. env.Run(core_builders.encryption_key_builder),
  157. )
  158. env.add_source_files(env.core_sources, gen_encrypt)
  159. # Certificates
  160. env.CommandNoCache(
  161. "#core/io/certs_compressed.gen.h",
  162. ["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
  163. env.Run(core_builders.make_certs_header),
  164. )
  165. # Authors
  166. env.CommandNoCache("#core/authors.gen.h", "#AUTHORS.md", env.Run(core_builders.make_authors_header))
  167. # Donors
  168. env.CommandNoCache("#core/donors.gen.h", "#DONORS.md", env.Run(core_builders.make_donors_header))
  169. # License
  170. env.CommandNoCache(
  171. "#core/license.gen.h", ["#COPYRIGHT.txt", "#LICENSE.txt"], env.Run(core_builders.make_license_header)
  172. )
  173. # Chain load SCsubs
  174. SConscript("os/SCsub")
  175. SConscript("math/SCsub")
  176. SConscript("crypto/SCsub")
  177. SConscript("io/SCsub")
  178. SConscript("debugger/SCsub")
  179. SConscript("input/SCsub")
  180. SConscript("variant/SCsub")
  181. SConscript("extension/SCsub")
  182. SConscript("object/SCsub")
  183. SConscript("templates/SCsub")
  184. SConscript("string/SCsub")
  185. SConscript("config/SCsub")
  186. SConscript("error/SCsub")
  187. # Build it all as a library
  188. lib = env.add_library("core", env.core_sources)
  189. env.Prepend(LIBS=[lib])
  190. # Needed to force rebuilding the core files when the thirdparty code is updated.
  191. env.Depends(lib, thirdparty_obj)