Merge pull request #353 from bruvzg/ios_support

Add iOS build support - couldn't test this but trust you @bruvzg  ;) 
@piiertho please do add CI support for this!
pull/356/head
Bastiaan Olij 2020-01-30 21:00:46 +11:00 committed by GitHub
commit 45e6801016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 2 deletions

View File

@ -2,6 +2,15 @@
import os import os
import sys 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: # Workaround for MinGW. See:
# http://www.scons.org/wiki/LongCmdLinesOnWin32 # http://www.scons.org/wiki/LongCmdLinesOnWin32
@ -64,7 +73,7 @@ opts.Add(EnumVariable(
'platform', 'platform',
'Target platform', 'Target platform',
host_platform, host_platform,
allowed_values=('linux', 'osx', 'windows', 'android'), allowed_values=('linux', 'osx', 'windows', 'android', 'ios'),
ignorecase=2 ignorecase=2
)) ))
opts.Add(EnumVariable( opts.Add(EnumVariable(
@ -114,6 +123,17 @@ opts.Add(EnumVariable(
'armv7', 'armv7',
['armv7','arm64v8','x86','x86_64'] ['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( opts.Add(
'android_api_level', 'android_api_level',
'Target Android API level', 'Target Android API level',
@ -194,6 +214,43 @@ elif env['platform'] == 'osx':
elif env['target'] == 'release': elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3']) 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': elif env['platform'] == 'windows':
if host_platform == 'windows' and not env['use_mingw']: if host_platform == 'windows' and not env['use_mingw']:
# MSVC # MSVC
@ -312,11 +369,17 @@ sources = []
add_sources(sources, 'src/core', 'cpp') add_sources(sources, 'src/core', 'cpp')
add_sources(sources, 'src/gen', '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( library = env.StaticLibrary(
target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format( target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format(
env['platform'], env['platform'],
env['target'], env['target'],
env['bits'] if env['platform'] != 'android' else env['android_arch'], arch_suffix,
env['LIBSUFFIX'] env['LIBSUFFIX']
), source=sources ), source=sources
) )