SCsub 2.6 KB

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