SCsub 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. Import("env")
  4. env_crypto = env.Clone()
  5. is_builtin = env["builtin_mbedtls"]
  6. has_module = env["module_mbedtls_enabled"]
  7. thirdparty_obj = []
  8. if is_builtin or not has_module:
  9. # Use our headers for builtin or if the module is not going to be compiled.
  10. # We decided not to depend on system mbedtls just for these few files that can
  11. # be easily extracted.
  12. env_crypto.Prepend(CPPPATH=["#thirdparty/mbedtls/include"])
  13. # MbedTLS core functions (for CryptoCore).
  14. # If the mbedtls module is compiled we don't need to add the .c files with our
  15. # custom config since they will be built by the module itself.
  16. # Only if the module is not enabled, we must compile here the required sources
  17. # to make a "light" build with only the necessary mbedtls files.
  18. if not has_module:
  19. # Minimal mbedTLS config file
  20. config_path = "thirdparty/mbedtls/include/godot_core_mbedtls_config.h"
  21. config_path = f"<{config_path}>" if env_crypto["ninja"] and env_crypto.msvc else f'\\"{config_path}\\"'
  22. env_crypto.Append(CPPDEFINES=[("MBEDTLS_CONFIG_FILE", config_path)])
  23. # Build minimal mbedTLS library (MD5/SHA/Base64/AES).
  24. env_thirdparty = env_crypto.Clone()
  25. env_thirdparty.disable_warnings()
  26. thirdparty_mbedtls_dir = "#thirdparty/mbedtls/library/"
  27. thirdparty_mbedtls_sources = [
  28. "aes.c",
  29. "base64.c",
  30. "constant_time.c",
  31. "ctr_drbg.c",
  32. "entropy.c",
  33. "md.c",
  34. "md5.c",
  35. "sha1.c",
  36. "sha256.c",
  37. "godot_core_mbedtls_platform.c",
  38. ]
  39. thirdparty_mbedtls_sources = [thirdparty_mbedtls_dir + file for file in thirdparty_mbedtls_sources]
  40. env_thirdparty.add_source_files(thirdparty_obj, thirdparty_mbedtls_sources)
  41. # Needed to force rebuilding the library when the configuration file is updated.
  42. env_thirdparty.Depends(thirdparty_obj, "#thirdparty/mbedtls/include/godot_core_mbedtls_config.h")
  43. env.core_sources += thirdparty_obj
  44. elif is_builtin:
  45. # Module mbedTLS config file
  46. config_path = "thirdparty/mbedtls/include/godot_module_mbedtls_config.h"
  47. config_path = f"<{config_path}>" if env_crypto["ninja"] and env_crypto.msvc else f'\\"{config_path}\\"'
  48. env_crypto.Append(CPPDEFINES=[("MBEDTLS_CONFIG_FILE", config_path)])
  49. # Needed to force rebuilding the core files when the configuration file is updated.
  50. thirdparty_obj = ["#thirdparty/mbedtls/include/godot_module_mbedtls_config.h"]
  51. # Godot source files
  52. core_obj = []
  53. env_crypto.add_source_files(core_obj, "*.cpp")
  54. env.core_sources += core_obj
  55. # Needed to force rebuilding the core files when the thirdparty library is updated.
  56. env.Depends(core_obj, thirdparty_obj)