|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | 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] |
5 | 14 |
|
6 | 15 | # Workaround for MinGW. See: |
7 | 16 | # http://www.scons.org/wiki/LongCmdLinesOnWin32 |
@@ -64,7 +73,7 @@ opts.Add(EnumVariable( |
64 | 73 | 'platform', |
65 | 74 | 'Target platform', |
66 | 75 | host_platform, |
67 | | - allowed_values=('linux', 'osx', 'windows', 'android'), |
| 76 | + allowed_values=('linux', 'osx', 'windows', 'android', 'ios'), |
68 | 77 | ignorecase=2 |
69 | 78 | )) |
70 | 79 | opts.Add(EnumVariable( |
@@ -114,6 +123,17 @@ opts.Add(EnumVariable( |
114 | 123 | 'armv7', |
115 | 124 | ['armv7','arm64v8','x86','x86_64'] |
116 | 125 | )) |
| 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 | +) |
117 | 137 | opts.Add( |
118 | 138 | 'android_api_level', |
119 | 139 | 'Target Android API level', |
@@ -194,6 +214,43 @@ elif env['platform'] == 'osx': |
194 | 214 | elif env['target'] == 'release': |
195 | 215 | env.Append(CCFLAGS=['-O3']) |
196 | 216 |
|
| 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 | + |
197 | 254 | elif env['platform'] == 'windows': |
198 | 255 | if host_platform == 'windows' and not env['use_mingw']: |
199 | 256 | # MSVC |
@@ -309,11 +366,17 @@ sources = [] |
309 | 366 | add_sources(sources, 'src/core', 'cpp') |
310 | 367 | add_sources(sources, 'src/gen', 'cpp') |
311 | 368 |
|
| 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 | + |
312 | 375 | library = env.StaticLibrary( |
313 | 376 | target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format( |
314 | 377 | env['platform'], |
315 | 378 | env['target'], |
316 | | - env['bits'] if env['platform'] != 'android' else env['android_arch'], |
| 379 | + arch_suffix, |
317 | 380 | env['LIBSUFFIX'] |
318 | 381 | ), source=sources |
319 | 382 | ) |
|
0 commit comments