Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f314b47

Browse files
committed
Add iOS build support.
1 parent 123d9f0 commit f314b47

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

SConstruct

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
import os
44
import sys
5+
import subprocess
6+
7+
if sys.version_info < (3,):
8+
def decode_utf8(x):
9+
return x
10+
else:
11+
import codecs
12+
def decode_utf8(x):
13+
return codecs.utf_8_decode(x)[0]
514

615
# Workaround for MinGW. See:
716
# http://www.scons.org/wiki/LongCmdLinesOnWin32
@@ -64,7 +73,7 @@ opts.Add(EnumVariable(
6473
'platform',
6574
'Target platform',
6675
host_platform,
67-
allowed_values=('linux', 'osx', 'windows', 'android'),
76+
allowed_values=('linux', 'osx', 'windows', 'android', 'ios'),
6877
ignorecase=2
6978
))
7079
opts.Add(EnumVariable(
@@ -114,6 +123,17 @@ opts.Add(EnumVariable(
114123
'armv7',
115124
['armv7','arm64v8','x86','x86_64']
116125
))
126+
opts.Add(EnumVariable(
127+
'ios_arch',
128+
'Target iOS architecture',
129+
'arm64',
130+
['armv7', 'arm64', 'x86_64']
131+
))
132+
opts.Add(
133+
'IPHONEPATH',
134+
'Path to iPhone toolchain',
135+
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain',
136+
)
117137
opts.Add(
118138
'android_api_level',
119139
'Target Android API level',
@@ -194,6 +214,43 @@ elif env['platform'] == 'osx':
194214
elif env['target'] == 'release':
195215
env.Append(CCFLAGS=['-O3'])
196216

217+
elif env['platform'] == 'ios':
218+
if env['ios_arch'] == 'x86_64':
219+
sdk_name = 'iphonesimulator'
220+
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
221+
else:
222+
sdk_name = 'iphoneos'
223+
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
224+
225+
try:
226+
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
227+
except (subprocess.CalledProcessError, OSError):
228+
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
229+
230+
compiler_path = env['IPHONEPATH'] + '/usr/bin/'
231+
env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
232+
233+
env['CC'] = compiler_path + 'clang'
234+
env['CXX'] = compiler_path + 'clang++'
235+
env['AR'] = compiler_path + 'ar'
236+
env['RANLIB'] = compiler_path + 'ranlib'
237+
238+
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', env['ios_arch'], '-isysroot', sdk_path])
239+
env.Append(LINKFLAGS=[
240+
'-arch',
241+
env['ios_arch'],
242+
'-framework',
243+
'Cocoa',
244+
'-Wl,-undefined,dynamic_lookup',
245+
'-isysroot', sdk_path,
246+
'-F' + sdk_path
247+
])
248+
249+
if env['target'] == 'debug':
250+
env.Append(CCFLAGS=['-Og'])
251+
elif env['target'] == 'release':
252+
env.Append(CCFLAGS=['-O3'])
253+
197254
elif env['platform'] == 'windows':
198255
if host_platform == 'windows' and not env['use_mingw']:
199256
# MSVC
@@ -309,11 +366,17 @@ sources = []
309366
add_sources(sources, 'src/core', 'cpp')
310367
add_sources(sources, 'src/gen', 'cpp')
311368

369+
arch_suffix = env['bits']
370+
if env['platform'] == 'android':
371+
arch_suffix = env['android_arch']
372+
if env['platform'] == 'ios':
373+
arch_suffix = env['ios_arch']
374+
312375
library = env.StaticLibrary(
313376
target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format(
314377
env['platform'],
315378
env['target'],
316-
env['bits'] if env['platform'] != 'android' else env['android_arch'],
379+
arch_suffix,
317380
env['LIBSUFFIX']
318381
), source=sources
319382
)

0 commit comments

Comments
 (0)