|
| 1 | +def build_library(env): |
| 2 | + mbedtls_bin = env.Dir("bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"])) |
| 3 | + is_msvc = env.get("is_msvc", False) |
| 4 | + c_flags = "-DMBEDTLS_SSL_DTLS_SRTP" |
| 5 | + if env["platform"] == "linux": |
| 6 | + # This is needed on some arch when building with the godot buildroot toolchain |
| 7 | + c_flags += " -fPIC" |
| 8 | + elif env["platform"] == "windows" and not is_msvc: |
| 9 | + c_flags += " -D__USE_MINGW_ANSI_STDIO=0" # See https://github.com/Mbed-TLS/mbedtls/issues/10161 |
| 10 | + |
| 11 | + mbedtls_config = { |
| 12 | + "CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release", |
| 13 | + "ENABLE_TESTING": 0, |
| 14 | + "ENABLE_PROGRAMS": 0, |
| 15 | + "CMAKE_INSTALL_PREFIX": env.Dir(mbedtls_bin).abspath, |
| 16 | + "CMAKE_C_FLAGS": c_flags, |
| 17 | + } |
| 18 | + lib_ext = ".lib" if is_msvc else ".a" |
| 19 | + lib_prefix = "" if is_msvc else "lib" |
| 20 | + mbedtls_libs = [ |
| 21 | + "/install/lib/{}mbedtls{}".format(lib_prefix, lib_ext), |
| 22 | + "/install/lib/{}mbedx509{}".format(lib_prefix, lib_ext), |
| 23 | + "/install/lib/{}mbedcrypto{}".format(lib_prefix, lib_ext), |
| 24 | + ] |
| 25 | + |
| 26 | + mbedtls_cmake_config = [ |
| 27 | + "/install/lib/cmake/MbedTLS/MbedTLSConfig.cmake", |
| 28 | + "/install/lib/cmake/MbedTLS/MbedTLSConfigVersion.cmake", |
| 29 | + "/install/lib/cmake/MbedTLS/MbedTLSTargets.cmake", |
| 30 | + ] |
| 31 | + |
| 32 | + # Build libdatachannel |
| 33 | + mbedtls = env.CMakeBuild( |
| 34 | + env.Dir("bin/thirdparty/mbedtls/"), |
| 35 | + env.Dir("thirdparty/mbedtls"), |
| 36 | + cmake_options=mbedtls_config, |
| 37 | + cmake_outputs=mbedtls_libs + mbedtls_cmake_config, |
| 38 | + install=True, |
| 39 | + ) |
| 40 | + |
| 41 | + # Configure env. |
| 42 | + if env["platform"] == "windows": |
| 43 | + env.PrependUnique(LIBS=["bcrypt", "ws2_32", "iphlpapi"]) |
| 44 | + if env["platform"] == "linux": |
| 45 | + env.PrependUnique(LIBS=["pthread"]) |
| 46 | + env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), mbedtls))) |
| 47 | + env.Append(CPPPATH=[env.Dir("thirdparty/mbedtls/include")]) |
| 48 | + |
| 49 | + return mbedtls |
| 50 | + |
| 51 | + |
| 52 | +def exists(env): |
| 53 | + return "CMake" in env |
| 54 | + |
| 55 | + |
| 56 | +def generate(env): |
| 57 | + mbedtls_install_dir = "bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"]) |
| 58 | + lib_ext = ".lib" if env.get("is_msvc", False) else ".a" |
| 59 | + mbedtls = env.File(mbedtls_install_dir + "/lib/libmbedtls" + lib_ext) |
| 60 | + crypto = env.File(mbedtls_install_dir + "/lib/libmbedcrypto" + lib_ext) |
| 61 | + x509 = env.File(mbedtls_install_dir + "/lib/libmbedx509" + lib_ext) |
| 62 | + includes = env.Dir("thirdparty/mbedtls/include") |
| 63 | + env.AddMethod(build_library, "BuildMbedTLS") |
| 64 | + env["MBEDTLS_LIBRARY"] = mbedtls.abspath |
| 65 | + env["MBEDTLS_CRYPTO_LIBRARY"] = crypto.abspath |
| 66 | + env["MBEDTLS_X509_LIBRARY"] = x509.abspath |
| 67 | + env["MBEDTLS_INCLUDE"] = includes.abspath |
0 commit comments