summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-06-30 17:03:26 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-01 23:58:01 +0200
commit9e287f7ceedc73b6e3b991be6f189dee7c586cc6 (patch)
tree7f36c8870a240d39563e08085368cbe185563e90
parenta374cf45106b2aa369cbcbda7e9beca737c59f8c (diff)
downloadfork-godot-webrtc-native-9e287f7ceedc73b6e3b991be6f189dee7c586cc6.tar.gz
fork-godot-webrtc-native-9e287f7ceedc73b6e3b991be6f189dee7c586cc6.tar.bz2
fork-godot-webrtc-native-9e287f7ceedc73b6e3b991be6f189dee7c586cc6.zip
Add mac and ios platforms. Fix GDNLibrary.
-rw-r--r--SConstruct90
-rw-r--r--misc/gdnlib.tres6
2 files changed, 91 insertions, 5 deletions
diff --git a/SConstruct b/SConstruct
index 7071c11..97a1601 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,6 +1,14 @@
#!python
-import os, sys, platform, json
+import os, sys, platform, json, subprocess
+
+if sys.version_info < (3,):
+ def decode_utf8(x):
+ return x
+else:
+ import codecs
+ def decode_utf8(x):
+ return codecs.utf_8_decode(x)[0]
def add_sources(sources, dirpath, extension):
@@ -12,7 +20,7 @@ def add_sources(sources, dirpath, extension):
def gen_gdnative_lib(target, source, env):
for t in target:
with open(t.srcnode().path, 'w') as w:
- w.write(source[0].get_contents().decode('utf8').replace('{GDNATIVE_PATH}', os.path.splitext(t.name)[0]).replace('{TARGET}', env['target']))
+ w.write(decode_utf8(source[0].get_contents()).replace('{GDNATIVE_PATH}', os.path.splitext(t.name)[0]).replace('{TARGET}', env['target']))
env = Environment()
@@ -52,6 +60,23 @@ opts.Add(
os.environ.get("ANDROID_NDK_ROOT", None)
)
+opts.Add(EnumVariable(
+ 'ios_arch',
+ 'Target iOS architecture',
+ 'arm64',
+ ['armv7', 'arm64', 'x86_64']
+))
+opts.Add(BoolVariable(
+ 'ios_simulator',
+ 'Target iOS Simulator',
+ False
+))
+opts.Add(
+ 'IPHONEPATH',
+ 'Path to iPhone toolchain',
+ '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain',
+)
+
# Update environment (parse options)
opts.Update(env)
@@ -59,6 +84,8 @@ target = env['target']
if target_platform == 'android':
target_arch = env['android_arch']
+elif target_platform == 'ios':
+ target_arch = env['ios_arch']
host_platform = platform.system()
# Local dependency paths, adapt them to your setup
@@ -96,6 +123,8 @@ if target_platform == 'linux':
elif target_arch == '64':
env.Append(CCFLAGS = [ '-m64' ])
env.Append(LINKFLAGS = [ '-m64' ])
+ # i386 does not like static libstdc++
+ env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++'])
elif target_platform == 'windows':
if host_platform == 'Windows':
@@ -125,6 +154,48 @@ elif target_platform == 'osx':
env.Append(CCFLAGS = [ '-g','-O3', '-std=c++14', '-arch', 'x86_64' ])
env.Append(LINKFLAGS = [ '-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup' ])
+ if env['target'] == 'debug':
+ env.Append(CCFLAGS=['-Og', '-g'])
+ elif env['target'] == 'release':
+ env.Append(CCFLAGS=['-O3'])
+
+elif target_platform == 'ios':
+ if env['ios_simulator']:
+ sdk_name = 'iphonesimulator'
+ env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
+ env['LIBSUFFIX'] = ".simulator" + env['LIBSUFFIX']
+ else:
+ sdk_name = 'iphoneos'
+ env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
+
+ try:
+ sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
+ except (subprocess.CalledProcessError, OSError):
+ raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
+
+ compiler_path = env['IPHONEPATH'] + '/usr/bin/'
+ env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
+
+ env['CC'] = compiler_path + 'clang'
+ env['CXX'] = compiler_path + 'clang++'
+ env['AR'] = compiler_path + 'ar'
+ env['RANLIB'] = compiler_path + 'ranlib'
+
+ env.Append(CCFLAGS=['-std=c++14', '-arch', env['ios_arch'], '-isysroot', sdk_path])
+ env.Append(LINKFLAGS=[
+ '-arch',
+ env['ios_arch'],
+ '-Wl,-undefined,dynamic_lookup',
+ '-isysroot', sdk_path,
+ '-F' + sdk_path
+ ])
+
+ if env['target'] == 'debug':
+ env.Append(CCFLAGS=['-Og', '-g'])
+ elif env['target'] == 'release':
+ env.Append(CCFLAGS=['-O3'])
+
+
elif target_platform == 'android':
# Verify NDK root
if not 'ANDROID_NDK_ROOT' in env:
@@ -185,7 +256,7 @@ else:
env.Append(CPPPATH=[godot_headers])
env.Append(CPPPATH=[godot_cpp_headers, godot_cpp_headers + '/core', godot_cpp_headers + '/gen'])
env.Append(LIBPATH=[godot_cpp_lib_dir])
-env.Append(LIBS=['%sgodot-cpp.%s.%s.%s' % (lib_prefix, target_platform, target, target_arch)])
+env.Append(LIBS=['%sgodot-cpp.%s.%s.%s%s' % (lib_prefix, target_platform, target, target_arch, ".simulator" if env["ios_simulator"] else "")])
# WebRTC stuff
webrtc_dir = "webrtc"
@@ -196,6 +267,7 @@ lib_path += {'32': '/x86',
'64': '/x64',
'armv7': '/arm',
'arm64v8': '/arm64',
+ 'arm64': '/arm64',
'x86': '/x86',
'x86_64': '/x64'}[target_arch]
@@ -207,7 +279,7 @@ else:
env.Append(CPPPATH=[webrtc_dir + "/include"])
if target_platform == "linux":
- env.Append(LIBS=[lib_name])
+ env.Append(LIBS=[lib_name, "atomic"])
env.Append(LIBPATH=[lib_path])
#env.Append(CCFLAGS=["-std=c++11"])
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_LINUX"])
@@ -228,6 +300,14 @@ elif target_platform == "windows":
elif target_platform == "osx":
env.Append(LIBS=[lib_name])
env.Append(LIBPATH=[lib_path])
+ env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_MAC"])
+ env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
+
+elif target_platform == 'ios':
+ env.Append(LIBS=[lib_name])
+ env.Append(LIBPATH=[lib_path])
+ env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_MAC", "-DWEBRTC_IOS"])
+ env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
elif target_platform == "android":
env.Append(LIBS=['log'])
@@ -261,4 +341,4 @@ Default(library)
gdnlib = 'webrtc'
if target != 'release':
gdnlib += '_debug'
-Default(env.GDNativeLibBuilder([os.path.join('bin', gdnlib, gdnlib + '.gdns')], ['misc/gdnlib.tres']))
+Default(env.GDNativeLibBuilder([os.path.join('bin', gdnlib, gdnlib + '.tres')], ['misc/gdnlib.tres']))
diff --git a/misc/gdnlib.tres b/misc/gdnlib.tres
index 52a0008..b708d99 100644
--- a/misc/gdnlib.tres
+++ b/misc/gdnlib.tres
@@ -3,6 +3,8 @@
[resource]
singleton = true
reloadable = false
+entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.64.dylib"
+entry/OSX.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.arm64.dylib"
entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/webrtc_native.windows.{TARGET}.64.dll"
entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/webrtc_native.windows.{TARGET}.32.dll"
entry/X11.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.64.so"
@@ -11,6 +13,10 @@ entry/Server.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.64.
entry/Server.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.32.so"
entry/Android.armeabi-v7a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.armv7.so"
entry/Android.arm64-v8a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.arm64v8.so"
+entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86_64.so"
+entry/Android.x86 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86.so"
+entry/iOS.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.arm64.dylib"
+entry/iOS.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.x86_64.dylib"
dependency/Windows.64 = [ ]
dependency/Windows.32 = [ ]
dependency/X11.64 = [ ]