0.2.0-dev Download ZIP
296 lines ·9.8 KB Raw
| 1 | #!/usr/bin/env python |
| 2 | from misc.utility.scons_hints import * |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | import core_builders |
| 7 | |
| 8 | import methods |
| 9 | |
| 10 | Import("env") |
| 11 | |
| 12 | env.core_sources = [] |
| 13 | |
| 14 | # Add required thirdparty code. |
| 15 | |
| 16 | thirdparty_obj = [] |
| 17 | |
| 18 | env_thirdparty = env.Clone() |
| 19 | env_thirdparty.disable_warnings() |
| 20 | |
| 21 | # Misc thirdparty code: header paths are hardcoded, we don't need to append |
| 22 | # to the include path (saves a few chars on the compiler invocation for touchy MSVC...) |
| 23 | thirdparty_misc_dir = "#thirdparty/misc/" |
| 24 | thirdparty_misc_sources = [ |
| 25 | # C sources |
| 26 | "fastlz.c", |
| 27 | "r128.c", |
| 28 | "smaz.c", |
| 29 | # C++ sources |
| 30 | "pcg.cpp", |
| 31 | "polypartition.cpp", |
| 32 | "smolv.cpp", |
| 33 | ] |
| 34 | thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources] |
| 35 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_misc_sources) |
| 36 | |
| 37 | # Brotli |
| 38 | if env["brotli"] and env["builtin_brotli"]: |
| 39 | thirdparty_brotli_dir = "#thirdparty/brotli/" |
| 40 | thirdparty_brotli_sources = [ |
| 41 | "common/constants.c", |
| 42 | "common/context.c", |
| 43 | "common/dictionary.c", |
| 44 | "common/platform.c", |
| 45 | "common/shared_dictionary.c", |
| 46 | "common/transform.c", |
| 47 | "dec/bit_reader.c", |
| 48 | "dec/decode.c", |
| 49 | "dec/huffman.c", |
| 50 | "dec/prefix.c", |
| 51 | "dec/state.c", |
| 52 | "dec/static_init.c", |
| 53 | ] |
| 54 | thirdparty_brotli_sources = [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources] |
| 55 | |
| 56 | env_thirdparty.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"]) |
| 57 | env.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"]) |
| 58 | |
| 59 | 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"): |
| 60 | env_thirdparty.Append(CPPDEFINES=["BROTLI_BUILD_PORTABLE"]) |
| 61 | |
| 62 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_brotli_sources) |
| 63 | |
| 64 | # PCRE2 |
| 65 | if env["builtin_pcre2"]: |
| 66 | thirdparty_pcre2_dir = "#thirdparty/pcre2/src/" |
| 67 | thirdparty_pcre2_sources = [ |
| 68 | "pcre2_auto_possess.c", |
| 69 | "pcre2_chartables.c", |
| 70 | "pcre2_chkdint.c", |
| 71 | "pcre2_compile.c", |
| 72 | "pcre2_compile_cgroup.c", |
| 73 | "pcre2_compile_class.c", |
| 74 | "pcre2_config.c", |
| 75 | "pcre2_context.c", |
| 76 | "pcre2_convert.c", |
| 77 | "pcre2_dfa_match.c", |
| 78 | "pcre2_error.c", |
| 79 | "pcre2_extuni.c", |
| 80 | "pcre2_find_bracket.c", |
| 81 | "pcre2_jit_compile.c", |
| 82 | "pcre2_maketables.c", |
| 83 | "pcre2_match.c", |
| 84 | "pcre2_match_data.c", |
| 85 | "pcre2_match_next.c", |
| 86 | "pcre2_newline.c", |
| 87 | "pcre2_ord2utf.c", |
| 88 | "pcre2_pattern_info.c", |
| 89 | "pcre2_script_run.c", |
| 90 | "pcre2_serialize.c", |
| 91 | "pcre2_string_utils.c", |
| 92 | "pcre2_study.c", |
| 93 | "pcre2_substitute.c", |
| 94 | "pcre2_substring.c", |
| 95 | "pcre2_tables.c", |
| 96 | "pcre2_ucd.c", |
| 97 | "pcre2_valid_utf.c", |
| 98 | "pcre2_xclass.c", |
| 99 | ] |
| 100 | |
| 101 | thirdparty_pcre2_sources = [thirdparty_pcre2_dir + file for file in thirdparty_pcre2_sources] |
| 102 | |
| 103 | thirdparty_pcre2_flags = ["PCRE2_STATIC", "HAVE_CONFIG_H", "SUPPORT_UNICODE", ("PCRE2_CODE_UNIT_WIDTH", 32)] |
| 104 | if env["builtin_pcre2_with_jit"]: |
| 105 | thirdparty_pcre2_flags.append("SUPPORT_JIT") |
| 106 | env_thirdparty.Append(CPPDEFINES=thirdparty_pcre2_flags) |
| 107 | env_thirdparty.Prepend(CPPPATH=[thirdparty_pcre2_dir]) |
| 108 | |
| 109 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_pcre2_sources) |
| 110 | |
| 111 | # Clipper2 Thirdparty source files used for polygon and polyline boolean operations. |
| 112 | if env["builtin_clipper2"]: |
| 113 | thirdparty_clipper_dir = "#thirdparty/clipper2/" |
| 114 | thirdparty_clipper_sources = [ |
| 115 | "src/clipper.engine.cpp", |
| 116 | "src/clipper.offset.cpp", |
| 117 | "src/clipper.rectclip.cpp", |
| 118 | ] |
| 119 | thirdparty_clipper_sources = [thirdparty_clipper_dir + file for file in thirdparty_clipper_sources] |
| 120 | |
| 121 | env_thirdparty.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"]) |
| 122 | env.Prepend(CPPPATH=[thirdparty_clipper_dir + "include"]) |
| 123 | |
| 124 | env_thirdparty.Append(CPPDEFINES=["CLIPPER2_ENABLED"]) |
| 125 | env.Append(CPPDEFINES=["CLIPPER2_ENABLED"]) |
| 126 | |
| 127 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_clipper_sources) |
| 128 | |
| 129 | # Zlib library, can be unbundled |
| 130 | if env["builtin_zlib"]: |
| 131 | thirdparty_zlib_dir = "#thirdparty/zlib/" |
| 132 | thirdparty_zlib_sources = [ |
| 133 | "adler32.c", |
| 134 | "compress.c", |
| 135 | "crc32.c", |
| 136 | "deflate.c", |
| 137 | "inffast.c", |
| 138 | "inflate.c", |
| 139 | "inftrees.c", |
| 140 | "trees.c", |
| 141 | "uncompr.c", |
| 142 | "zutil.c", |
| 143 | ] |
| 144 | thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources] |
| 145 | |
| 146 | env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir]) |
| 147 | # Needs to be available in main env too |
| 148 | env.Prepend(CPPPATH=[thirdparty_zlib_dir]) |
| 149 | if env.dev_build: |
| 150 | env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"]) |
| 151 | # Affects headers so it should also be defined for Godot code |
| 152 | env.Append(CPPDEFINES=["ZLIB_DEBUG"]) |
| 153 | |
| 154 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources) |
| 155 | |
| 156 | # Minizip library, could be unbundled in theory |
| 157 | # However, our version has some custom modifications, so it won't compile with the system one |
| 158 | thirdparty_minizip_dir = "#thirdparty/minizip/" |
| 159 | thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"] |
| 160 | thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources] |
| 161 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources) |
| 162 | |
| 163 | # Zstd library, can be unbundled |
| 164 | if env["builtin_zstd"]: |
| 165 | thirdparty_zstd_dir = "#thirdparty/zstd/" |
| 166 | thirdparty_zstd_sources = [ |
| 167 | "common/debug.c", |
| 168 | "common/entropy_common.c", |
| 169 | "common/error_private.c", |
| 170 | "common/fse_decompress.c", |
| 171 | "common/pool.c", |
| 172 | "common/threading.c", |
| 173 | "common/xxhash.c", |
| 174 | "common/zstd_common.c", |
| 175 | "compress/fse_compress.c", |
| 176 | "compress/hist.c", |
| 177 | "compress/huf_compress.c", |
| 178 | "compress/zstd_compress.c", |
| 179 | "compress/zstd_double_fast.c", |
| 180 | "compress/zstd_fast.c", |
| 181 | "compress/zstd_lazy.c", |
| 182 | "compress/zstd_ldm.c", |
| 183 | "compress/zstd_opt.c", |
| 184 | "compress/zstd_preSplit.c", |
| 185 | "compress/zstdmt_compress.c", |
| 186 | "compress/zstd_compress_literals.c", |
| 187 | "compress/zstd_compress_sequences.c", |
| 188 | "compress/zstd_compress_superblock.c", |
| 189 | "decompress/huf_decompress.c", |
| 190 | "decompress/zstd_ddict.c", |
| 191 | "decompress/zstd_decompress_block.c", |
| 192 | "decompress/zstd_decompress.c", |
| 193 | ] |
| 194 | if ( |
| 195 | env["platform"] in ["android", "ios", "linuxbsd", "macos", "windows"] |
| 196 | and env["arch"] == "x86_64" |
| 197 | and not env.msvc |
| 198 | ): |
| 199 | # Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h |
| 200 | thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S") |
| 201 | thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources] |
| 202 | |
| 203 | env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"]) |
| 204 | env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"]) |
| 205 | env.Prepend(CPPPATH=thirdparty_zstd_dir) |
| 206 | # Also needed in main env includes will trigger warnings |
| 207 | env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"]) |
| 208 | |
| 209 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources) |
| 210 | |
| 211 | |
| 212 | env.core_sources += thirdparty_obj |
| 213 | |
| 214 | |
| 215 | # Godot source files |
| 216 | env.add_source_files(env.core_sources, "*.cpp") |
| 217 | |
| 218 | # Generate disabled classes |
| 219 | env.CommandNoCache( |
| 220 | "disabled_classes.gen.h", env.Value(env.disabled_classes), env.Run(core_builders.disabled_class_builder) |
| 221 | ) |
| 222 | |
| 223 | # Generate version info |
| 224 | env.CommandNoCache( |
| 225 | "version_generated.gen.h", |
| 226 | env.Value(methods.get_version_info(env.module_version_string)), |
| 227 | env.Run(core_builders.version_info_builder), |
| 228 | ) |
| 229 | |
| 230 | # Generate version hash |
| 231 | gen_hash = env.CommandNoCache( |
| 232 | "version_hash.gen.cpp", env.Value(methods.get_git_info()), env.Run(core_builders.version_hash_builder) |
| 233 | ) |
| 234 | env.add_source_files(env.core_sources, gen_hash) |
| 235 | |
| 236 | # Generate AES256 script encryption key |
| 237 | encryption_key = os.environ.get("SCRIPT_AES256_ENCRYPTION_KEY") |
| 238 | encryption_key_var = "SCRIPT_AES256_ENCRYPTION_KEY" |
| 239 | if encryption_key is None: |
| 240 | # Fallback to the environment variable used by Godot on export. |
| 241 | # This allows setting only one environment variable for both compiling and exporting. |
| 242 | encryption_key = os.environ.get("GODOT_SCRIPT_ENCRYPTION_KEY") |
| 243 | encryption_key_var = "GODOT_SCRIPT_ENCRYPTION_KEY" |
| 244 | if encryption_key: |
| 245 | print( |
| 246 | f"\n*** IMPORTANT: Compiling Godot with custom `{encryption_key_var}` set as environment variable." |
| 247 | "\n*** Make sure to use templates compiled with this key when exporting a project with encryption.\n" |
| 248 | ) |
| 249 | gen_encrypt = env.CommandNoCache( |
| 250 | "script_encryption_key.gen.cpp", |
| 251 | env.Value(encryption_key), |
| 252 | env.Run(core_builders.encryption_key_builder), |
| 253 | ) |
| 254 | env.add_source_files(env.core_sources, gen_encrypt) |
| 255 | |
| 256 | # Certificates |
| 257 | env.CommandNoCache( |
| 258 | "#core/io/certs_compressed.gen.h", |
| 259 | ["#thirdparty/certs/ca-bundle.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])], |
| 260 | env.Run(core_builders.make_certs_header), |
| 261 | ) |
| 262 | |
| 263 | # Authors |
| 264 | env.CommandNoCache("#core/authors.gen.h", "#AUTHORS.md", env.Run(core_builders.make_authors_header)) |
| 265 | |
| 266 | # Donors |
| 267 | env.CommandNoCache("#core/donors.gen.h", "#DONORS.md", env.Run(core_builders.make_donors_header)) |
| 268 | |
| 269 | # License |
| 270 | env.CommandNoCache( |
| 271 | "#core/license.gen.h", ["#COPYRIGHT.txt", "#LICENSE.txt"], env.Run(core_builders.make_license_header) |
| 272 | ) |
| 273 | |
| 274 | # Chain load SCsubs |
| 275 | SConscript("profiling/SCsub") |
| 276 | SConscript("os/SCsub") |
| 277 | SConscript("math/SCsub") |
| 278 | SConscript("crypto/SCsub") |
| 279 | SConscript("io/SCsub") |
| 280 | SConscript("debugger/SCsub") |
| 281 | SConscript("input/SCsub") |
| 282 | SConscript("variant/SCsub") |
| 283 | SConscript("extension/SCsub") |
| 284 | SConscript("object/SCsub") |
| 285 | SConscript("templates/SCsub") |
| 286 | SConscript("string/SCsub") |
| 287 | SConscript("config/SCsub") |
| 288 | SConscript("error/SCsub") |
| 289 | |
| 290 | |
| 291 | # Build it all as a library |
| 292 | lib = env.add_library("core", env.core_sources) |
| 293 | env.Prepend(LIBS=[lib]) |
| 294 | |
| 295 | # Needed to force rebuilding the core files when the thirdparty code is updated. |
| 296 | env.Depends(lib, thirdparty_obj) |