detect.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import os
  2. import string
  3. import sys
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "iOS"
  8. def can_build():
  9. if sys.platform == 'darwin' or ("OSXCROSS_IOS" in os.environ):
  10. return True
  11. return False
  12. def get_opts():
  13. from SCons.Variables import BoolVariable
  14. return [
  15. ('IPHONEPLATFORM', 'Name of the iPhone platform', 'iPhoneOS'),
  16. ('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
  17. ('IPHONESDK', 'Path to the iPhone SDK', '/Applications/Xcode.app/Contents/Developer/Platforms/${IPHONEPLATFORM}.platform/Developer/SDKs/${IPHONEPLATFORM}.sdk/'),
  18. BoolVariable('game_center', 'Support for game center', True),
  19. BoolVariable('store_kit', 'Support for in-app store', True),
  20. BoolVariable('icloud', 'Support for iCloud', True),
  21. BoolVariable('ios_exceptions', 'Enable exceptions', False),
  22. ('ios_triple', 'Triple for ios toolchain', ''),
  23. BoolVariable('ios_sim', 'Build simulator binary', False),
  24. ]
  25. def get_flags():
  26. return [
  27. ('tools', False),
  28. ]
  29. def configure(env):
  30. ## Build type
  31. if (env["target"].startswith("release")):
  32. env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1'])
  33. env.Append(CPPFLAGS=['-O2', '-flto', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations'])
  34. env.Append(LINKFLAGS=['-O2', '-flto'])
  35. if env["target"] == "release_debug":
  36. env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
  37. elif (env["target"] == "debug"):
  38. env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  39. ## Architecture
  40. if env["ios_sim"] or env["arch"] == "x86": # i386, simulator
  41. env["arch"] = "x86"
  42. env["bits"] = "32"
  43. elif (env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32"): # arm
  44. env["arch"] = "arm"
  45. env["bits"] = "32"
  46. else: # armv64
  47. env["arch"] = "arm64"
  48. env["bits"] = "64"
  49. ## Compiler configuration
  50. env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
  51. env['CC'] = '$IPHONEPATH/usr/bin/${ios_triple}clang'
  52. env['CXX'] = '$IPHONEPATH/usr/bin/${ios_triple}clang++'
  53. env['AR'] = '$IPHONEPATH/usr/bin/${ios_triple}ar'
  54. env['RANLIB'] = '$IPHONEPATH/usr/bin/${ios_triple}ranlib'
  55. env['S_compiler'] = '$IPHONEPATH/Developer/usr/bin/gcc'
  56. ## Compile flags
  57. if (env["arch"] == "x86"):
  58. env['IPHONEPLATFORM'] = 'iPhoneSimulator'
  59. env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
  60. env.Append(CCFLAGS='-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"'.split())
  61. elif (env["arch"] == "arm"):
  62. env.Append(CCFLAGS='-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=9.0 -MMD -MT dependencies'.split())
  63. elif (env["arch"] == "arm64"):
  64. env.Append(CCFLAGS='-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=9.0 -isysroot $IPHONESDK'.split())
  65. env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
  66. env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
  67. if env['ios_exceptions']:
  68. env.Append(CPPFLAGS=['-fexceptions'])
  69. else:
  70. env.Append(CPPFLAGS=['-fno-exceptions'])
  71. ## Link flags
  72. if (env["arch"] == "x86"):
  73. env.Append(LINKFLAGS=['-arch', 'i386', '-mios-simulator-version-min=4.3',
  74. '-isysroot', '$IPHONESDK',
  75. '-Xlinker',
  76. '-objc_abi_version',
  77. '-Xlinker', '2',
  78. '-F$IPHONESDK',
  79. ])
  80. elif (env["arch"] == "arm"):
  81. env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=9.0'])
  82. if (env["arch"] == "arm64"):
  83. env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=9.0'])
  84. env.Append(LINKFLAGS=['-isysroot', '$IPHONESDK',
  85. '-framework', 'AudioToolbox',
  86. '-framework', 'AVFoundation',
  87. '-framework', 'CoreAudio',
  88. '-framework', 'CoreGraphics',
  89. '-framework', 'CoreMedia',
  90. '-framework', 'CoreMotion',
  91. '-framework', 'Foundation',
  92. '-framework', 'GameController',
  93. '-framework', 'MediaPlayer',
  94. '-framework', 'OpenGLES',
  95. '-framework', 'QuartzCore',
  96. '-framework', 'Security',
  97. '-framework', 'SystemConfiguration',
  98. '-framework', 'UIKit',
  99. ])
  100. # Feature options
  101. if env['game_center']:
  102. env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
  103. env.Append(LINKFLAGS=['-framework', 'GameKit'])
  104. if env['store_kit']:
  105. env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
  106. env.Append(LINKFLAGS=['-framework', 'StoreKit'])
  107. if env['icloud']:
  108. env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
  109. env.Append(CPPPATH=['$IPHONESDK/usr/include',
  110. '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers',
  111. '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers',
  112. ])
  113. env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
  114. env.Append(CPPPATH=['#platform/iphone'])
  115. env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT', '-DCOREAUDIO_ENABLED'])
  116. # TODO: Move that to opus module's config
  117. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  118. env.opus_fixed_point = "yes"
  119. if (env["arch"] == "arm"):
  120. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  121. elif (env["arch"] == "arm64"):
  122. env.Append(CFLAGS=["-DOPUS_ARM64_OPT"])