summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2023-06-29 14:04:53 +0200
committerGitHub <noreply@github.com>2023-06-29 14:04:53 +0200
commit931a7551f56e28b440a9887b557eecc9a840bda5 (patch)
treea6923c943d3e1a9bc988cc6a150c8900fbcfbe40
parentae0dd0626a025968a256ac659d6290eb66891c81 (diff)
parent0771084b5475a560ccdc03e6fa0e3c30f95dd638 (diff)
downloadfork-godot-webrtc-native-931a7551f56e28b440a9887b557eecc9a840bda5.tar.gz
fork-godot-webrtc-native-931a7551f56e28b440a9887b557eecc9a840bda5.tar.bz2
fork-godot-webrtc-native-931a7551f56e28b440a9887b557eecc9a840bda5.zip
Merge pull request #107 from Faless/build/cmake_helper
[SCons] Simplify building cmake libraries.
-rw-r--r--tools/cmake.py13
-rw-r--r--tools/rtc.py57
2 files changed, 37 insertions, 33 deletions
diff --git a/tools/cmake.py b/tools/cmake.py
index c590860..39957d8 100644
--- a/tools/cmake.py
+++ b/tools/cmake.py
@@ -101,6 +101,18 @@ def cmake_generator(target, source, env, for_signature):
]
+def cmake_build(env, target_dir, source_dir, cmake_outputs=[], cmake_targets=[], cmake_options=[], dependencies=[]):
+ cmake_env = env.Clone()
+ target = env.Dir("{}/{}/{}".format(target_dir, env["platform"], env["arch"]))
+ source = env.Dir(source_dir)
+ builder_targets = [target] + [str(target) + "/" + f for f in cmake_outputs]
+ builder_sources = [source] + dependencies
+ cmake_env.Append(CMAKECONFFLAGS=["-D%s=%s" % it for it in cmake_options.items()])
+ if len(cmake_targets) > 0:
+ cmake_env.Append(CMAKEBUILDFLAGS=["-t"] + [t for t in cmake_targets])
+ return cmake_env.CMake(builder_targets, builder_sources)
+
+
def options(opts):
opts.Add("cmake_default_flags", "Default CMake platform flags override, will be autodetected if not specified.", "")
@@ -120,3 +132,4 @@ def generate(env):
env["CMAKEBUILDFLAGS"] = SCons.Util.CLVar("")
env["CMAKEBUILDCOM"] = "$CMAKE --build ${TARGET.dir} $CMAKEBUILDFLAGS -j$CMAKEBUILDJOBS"
env["BUILDERS"]["CMake"] = SCons.Builder.Builder(generator=cmake_generator, emitter=cmake_emitter)
+ env.AddMethod(cmake_build, "CMakeBuild")
diff --git a/tools/rtc.py b/tools/rtc.py
index a487b08..6882bb4 100644
--- a/tools/rtc.py
+++ b/tools/rtc.py
@@ -1,8 +1,8 @@
import os
-def rtc_cmake_config(env):
- config = {
+def build_library(env, ssl):
+ rtc_config = {
"CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release",
"USE_NICE": 0,
"NO_WEBSOCKET": 1,
@@ -15,21 +15,31 @@ def rtc_cmake_config(env):
"OPENSSL_CRYPTO_LIBRARY": env["SSL_CRYPTO_LIBRARY"],
"OPENSSL_ROOT_DIR": env["SSL_INSTALL"],
}
- return config
-
-
-def build_library(env, ssl):
+ is_msvc = env.get("is_msvc", False)
+ lib_ext = ".lib" if is_msvc else ".a"
+ lib_prefix = "" if is_msvc else "lib"
+ rtc_libs = [
+ "{}datachannel-static{}".format(lib_prefix, lib_ext),
+ "deps/libjuice/{}juice-static{}".format(lib_prefix, lib_ext),
+ "deps/libsrtp/{}srtp2{}".format(lib_prefix, lib_ext),
+ "deps/usrsctp/usrsctplib/{}usrsctp{}".format(lib_prefix, lib_ext),
+ ]
+ # Build libdatachannel
+ rtc = env.CMakeBuild(
+ "#bin/thirdparty/libdatachannel/",
+ "#thirdparty/libdatachannel",
+ cmake_options=rtc_config,
+ cmake_outputs=rtc_libs,
+ cmake_targets=["datachannel-static"],
+ dependencies=ssl,
+ )
+
+ # Configure env.
if env["platform"] == "windows":
env.PrependUnique(LIBS=["iphlpapi", "bcrypt"])
+ env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), rtc)))
+ env.Append(CPPPATH=["#thirdparty/libdatachannel/include"])
- env.Prepend(LIBS=env["RTC_LIBS"])
-
- rtc_env = env.Clone()
- rtc_targets = [env.Dir(env["RTC_BUILD"])] + env["RTC_LIBS"]
- rtc_sources = [env.Dir(env["RTC_SOURCE"])] + ssl
- rtc_env.Append(CMAKECONFFLAGS=["-D%s=%s" % it for it in rtc_cmake_config(env).items()])
- rtc_env.Append(CMAKEBUILDFLAGS=["-t", "datachannel-static"])
- rtc = rtc_env.CMake(rtc_targets, rtc_sources)
return rtc
@@ -38,23 +48,4 @@ def exists(env):
def generate(env):
- env["RTC_SOURCE"] = env.Dir("#thirdparty/libdatachannel").abspath
- env["RTC_BUILD"] = env.Dir("#bin/thirdparty/libdatachannel/{}/{}".format(env["platform"], env["arch"])).abspath
- env["RTC_INCLUDE"] = env["RTC_SOURCE"] + "/include"
- lib_ext = ".a"
- lib_prefix = "lib"
- if env.get("is_msvc", False):
- lib_ext = ".lib"
- lib_prefix = ""
- env["RTC_LIBS"] = [
- env.File(env["RTC_BUILD"] + "/" + lib)
- for lib in [
- "{}datachannel-static{}".format(lib_prefix, lib_ext),
- "deps/libjuice/{}juice-static{}".format(lib_prefix, lib_ext),
- "deps/libsrtp/{}srtp2{}".format(lib_prefix, lib_ext),
- "deps/usrsctp/usrsctplib/{}usrsctp{}".format(lib_prefix, lib_ext),
- ]
- ]
env.AddMethod(build_library, "BuildLibDataChannel")
- env.Append(LIBPATH=[env["RTC_BUILD"]])
- env.Append(CPPPATH=[env["RTC_INCLUDE"]])