summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2019-11-26 21:26:06 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2019-11-26 21:26:06 +0200
commitf314b478434e78401582ab76261efcb2b194dd2c (patch)
treec511b6625ae12dc40566d836a4ca79800c2f09d8
parent123d9f0e9264dcc7206888fc96419b32feef00c8 (diff)
downloadredot-cpp-f314b478434e78401582ab76261efcb2b194dd2c.tar.gz
Add iOS build support.
-rw-r--r--SConstruct67
1 files changed, 65 insertions, 2 deletions
diff --git a/SConstruct b/SConstruct
index 65a26b8..2370659 100644
--- a/SConstruct
+++ b/SConstruct
@@ -2,6 +2,15 @@
import os
import sys
+import 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]
# Workaround for MinGW. See:
# http://www.scons.org/wiki/LongCmdLinesOnWin32
@@ -64,7 +73,7 @@ opts.Add(EnumVariable(
'platform',
'Target platform',
host_platform,
- allowed_values=('linux', 'osx', 'windows', 'android'),
+ allowed_values=('linux', 'osx', 'windows', 'android', 'ios'),
ignorecase=2
))
opts.Add(EnumVariable(
@@ -114,6 +123,17 @@ opts.Add(EnumVariable(
'armv7',
['armv7','arm64v8','x86','x86_64']
))
+opts.Add(EnumVariable(
+ 'ios_arch',
+ 'Target iOS architecture',
+ 'arm64',
+ ['armv7', 'arm64', 'x86_64']
+))
+opts.Add(
+ 'IPHONEPATH',
+ 'Path to iPhone toolchain',
+ '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain',
+)
opts.Add(
'android_api_level',
'Target Android API level',
@@ -194,6 +214,43 @@ elif env['platform'] == 'osx':
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
+elif env['platform'] == 'ios':
+ if env['ios_arch'] == 'x86_64':
+ sdk_name = 'iphonesimulator'
+ env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
+ 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=['-g', '-std=c++14', '-arch', env['ios_arch'], '-isysroot', sdk_path])
+ env.Append(LINKFLAGS=[
+ '-arch',
+ env['ios_arch'],
+ '-framework',
+ 'Cocoa',
+ '-Wl,-undefined,dynamic_lookup',
+ '-isysroot', sdk_path,
+ '-F' + sdk_path
+ ])
+
+ if env['target'] == 'debug':
+ env.Append(CCFLAGS=['-Og'])
+ elif env['target'] == 'release':
+ env.Append(CCFLAGS=['-O3'])
+
elif env['platform'] == 'windows':
if host_platform == 'windows' and not env['use_mingw']:
# MSVC
@@ -309,11 +366,17 @@ sources = []
add_sources(sources, 'src/core', 'cpp')
add_sources(sources, 'src/gen', 'cpp')
+arch_suffix = env['bits']
+if env['platform'] == 'android':
+ arch_suffix = env['android_arch']
+if env['platform'] == 'ios':
+ arch_suffix = env['ios_arch']
+
library = env.StaticLibrary(
target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format(
env['platform'],
env['target'],
- env['bits'] if env['platform'] != 'android' else env['android_arch'],
+ arch_suffix,
env['LIBSUFFIX']
), source=sources
)