0.2.0-dev Download ZIP
102 lines ·4.2 KB Raw
| 1 | #!/usr/bin/env python |
| 2 | from misc.utility.scons_hints import * |
| 3 | |
| 4 | Import("env") |
| 5 | |
| 6 | |
| 7 | def _escape_define(env, config): |
| 8 | return f"<{config}>" if env["ninja"] and env.msvc else f'\\"{config}\\"' |
| 9 | |
| 10 | |
| 11 | env_crypto = env.Clone() |
| 12 | env_crypto.AddMethod(_escape_define, "EscapeDefine") |
| 13 | |
| 14 | is_builtin = env["builtin_mbedtls"] |
| 15 | has_module = env["module_mbedtls_enabled"] |
| 16 | thirdparty_obj = [] |
| 17 | configs = [] |
| 18 | |
| 19 | if is_builtin or not has_module: |
| 20 | # Use our headers for builtin or if the module is not going to be compiled. |
| 21 | # We decided not to depend on system mbedtls and bundle a minimal version |
| 22 | # when building without the module. |
| 23 | env_crypto.Prepend( |
| 24 | CPPPATH=[ |
| 25 | "#thirdparty/mbedtls/godot/", |
| 26 | "#thirdparty/mbedtls/include/", |
| 27 | "#thirdparty/mbedtls/tf-psa-crypto/include/", |
| 28 | "#thirdparty/mbedtls/tf-psa-crypto/drivers/builtin/include/", |
| 29 | ] |
| 30 | ) |
| 31 | env_crypto.Append( |
| 32 | CPPDEFINES=[ |
| 33 | ("TF_PSA_CRYPTO_CONFIG_FILE", env_crypto.EscapeDefine("godot_psa_config.h")), |
| 34 | ("MBEDTLS_CONFIG_FILE", env_crypto.EscapeDefine("godot_mbedtls_config.h")), |
| 35 | ] |
| 36 | ) |
| 37 | configs = ["#thirdparty/mbedtls/godot/godot_psa_config.h", "#thirdparty/mbedtls/godot/godot_mbedtls_config.h"] |
| 38 | if not has_module: |
| 39 | env_crypto.Append(CPPDEFINES=["GODOT_MBEDTLS_LIGHT"]) |
| 40 | # Our custom mbedTLS platform functions |
| 41 | platform_obj = [] |
| 42 | env_crypto.add_source_files(platform_obj, ["#thirdparty/mbedtls/godot/godot_mbedtls_platform.cpp"]) |
| 43 | env.core_sources += platform_obj |
| 44 | env.Depends(platform_obj, configs) |
| 45 | |
| 46 | # MbedTLS core functions (for CryptoCore). |
| 47 | # If the mbedtls module is compiled we don't need to add the .c files with our |
| 48 | # custom config since they will be built by the module itself. |
| 49 | # Only if the module is not enabled, we must compile here the required sources |
| 50 | # to make a "light" build with only the necessary mbedtls files. |
| 51 | if not has_module: |
| 52 | # Build minimal mbedTLS library (MD5/SHA/Base64/AES). |
| 53 | env_thirdparty = env_crypto.Clone() |
| 54 | env_thirdparty.disable_warnings() |
| 55 | psa_dir = "#thirdparty/mbedtls/tf-psa-crypto/" |
| 56 | env_thirdparty.Prepend( |
| 57 | CPPPATH=[ |
| 58 | psa_dir + d |
| 59 | for d in ["include/", "core/", "dispatch/", "extras", "platform/", "utilities/", "drivers/builtin/src/"] |
| 60 | ] |
| 61 | ) |
| 62 | env_thirdparty.Prepend(CPPPATH=["#thirdparty/mbedtls/tf-psa-crypto/drivers/builtin/include/"]) |
| 63 | |
| 64 | thirdparty_mbedtls_dir = "#thirdparty/mbedtls/" |
| 65 | thirdparty_mbedtls_sources = [ |
| 66 | "tf-psa-crypto/core/psa_crypto.c", |
| 67 | "tf-psa-crypto/core/psa_crypto_client.c", |
| 68 | "tf-psa-crypto/core/psa_crypto_driver_wrappers_no_static.c", |
| 69 | "tf-psa-crypto/core/psa_crypto_random.c", |
| 70 | "tf-psa-crypto/core/psa_crypto_slot_management.c", |
| 71 | "tf-psa-crypto/utilities/base64.c", |
| 72 | "tf-psa-crypto/utilities/constant_time.c", |
| 73 | "tf-psa-crypto/platform/threading.c", |
| 74 | "tf-psa-crypto/extras/md.c", |
| 75 | "tf-psa-crypto/drivers/builtin/src/aes.c", |
| 76 | "tf-psa-crypto/drivers/builtin/src/ctr_drbg.c", |
| 77 | "tf-psa-crypto/drivers/builtin/src/cipher.c", |
| 78 | "tf-psa-crypto/drivers/builtin/src/cipher_wrap.c", |
| 79 | "tf-psa-crypto/drivers/builtin/src/entropy.c", |
| 80 | "tf-psa-crypto/drivers/builtin/src/entropy_poll.c", |
| 81 | "tf-psa-crypto/drivers/builtin/src/md5.c", |
| 82 | "tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.c", |
| 83 | "tf-psa-crypto/drivers/builtin/src/psa_crypto_hash.c", |
| 84 | "tf-psa-crypto/drivers/builtin/src/psa_crypto_rsa.c", |
| 85 | "tf-psa-crypto/drivers/builtin/src/psa_util_internal.c", |
| 86 | "tf-psa-crypto/drivers/builtin/src/sha1.c", |
| 87 | "tf-psa-crypto/drivers/builtin/src/sha256.c", |
| 88 | ] |
| 89 | thirdparty_mbedtls_sources = [thirdparty_mbedtls_dir + file for file in thirdparty_mbedtls_sources] |
| 90 | env_thirdparty.add_source_files(thirdparty_obj, thirdparty_mbedtls_sources) |
| 91 | # Needed to force rebuilding the library when the configuration file is updated. |
| 92 | env_thirdparty.Depends(thirdparty_obj, configs) |
| 93 | env.core_sources += thirdparty_obj |
| 94 | |
| 95 | # Godot source files |
| 96 | core_obj = [] |
| 97 | |
| 98 | env_crypto.add_source_files(core_obj, "*.cpp") |
| 99 | env.core_sources += core_obj |
| 100 | |
| 101 | # Needed to force rebuilding the core files when the thirdparty library is updated. |
| 102 | env.Depends(core_obj, thirdparty_obj + configs) |