detect.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 (deprecated, use arch=x86 or arch=x86_64)', 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', '-ftree-vectorize', '-fomit-frame-pointer'])
  34. env.Append(LINKFLAGS=['-O2'])
  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. if (env["use_lto"]):
  40. env.Append(CPPFLAGS=['-flto'])
  41. env.Append(LINKFLAGS=['-flto'])
  42. ## Architecture
  43. if env["ios_sim"] and not ("arch" in env):
  44. env["arch"] = "x86"
  45. if env["arch"] == "x86": # i386, simulator
  46. env["bits"] = "32"
  47. elif env["arch"] == "x86_64":
  48. env["bits"] = "64"
  49. elif (env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32"): # arm
  50. env["arch"] = "arm"
  51. env["bits"] = "32"
  52. else: # armv64
  53. env["arch"] = "arm64"
  54. env["bits"] = "64"
  55. ## Compiler configuration
  56. env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
  57. compiler_path = '$IPHONEPATH/usr/bin/${ios_triple}'
  58. s_compiler_path = '$IPHONEPATH/Developer/usr/bin/'
  59. ccache_path = os.environ.get("CCACHE")
  60. if ccache_path == None:
  61. env['CC'] = compiler_path + 'clang'
  62. env['CXX'] = compiler_path + 'clang++'
  63. env['S_compiler'] = s_compiler_path + 'gcc'
  64. else:
  65. # there aren't any ccache wrappers available for iOS,
  66. # to enable caching we need to prepend the path to the ccache binary
  67. env['CC'] = ccache_path + ' ' + compiler_path + 'clang'
  68. env['CXX'] = ccache_path + ' ' + compiler_path + 'clang++'
  69. env['S_compiler'] = ccache_path + ' ' + s_compiler_path + 'gcc'
  70. env['AR'] = compiler_path + 'ar'
  71. env['RANLIB'] = compiler_path + 'ranlib'
  72. ## Compile flags
  73. if (env["arch"] == "x86" or env["arch"] == "x86_64"):
  74. env['IPHONEPLATFORM'] = 'iPhoneSimulator'
  75. env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
  76. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  77. env.Append(CCFLAGS=('-arch ' + arch_flag + ' -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -isysroot $IPHONESDK -mios-simulator-version-min=9.0 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"').split())
  78. elif (env["arch"] == "arm"):
  79. 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())
  80. elif (env["arch"] == "arm64"):
  81. 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())
  82. env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
  83. env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
  84. if env['ios_exceptions']:
  85. env.Append(CPPFLAGS=['-fexceptions'])
  86. else:
  87. env.Append(CPPFLAGS=['-fno-exceptions'])
  88. ## Link flags
  89. if (env["arch"] == "x86" or env["arch"] == "x86_64"):
  90. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  91. env.Append(LINKFLAGS=['-arch', arch_flag, '-mios-simulator-version-min=9.0',
  92. '-isysroot', '$IPHONESDK',
  93. '-Xlinker',
  94. '-objc_abi_version',
  95. '-Xlinker', '2',
  96. '-F$IPHONESDK',
  97. ])
  98. elif (env["arch"] == "arm"):
  99. env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=9.0'])
  100. if (env["arch"] == "arm64"):
  101. env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=9.0'])
  102. env.Append(LINKFLAGS=['-isysroot', '$IPHONESDK',
  103. '-framework', 'AudioToolbox',
  104. '-framework', 'AVFoundation',
  105. '-framework', 'CoreAudio',
  106. '-framework', 'CoreGraphics',
  107. '-framework', 'CoreMedia',
  108. '-framework', 'CoreMotion',
  109. '-framework', 'Foundation',
  110. '-framework', 'GameController',
  111. '-framework', 'MediaPlayer',
  112. '-framework', 'OpenGLES',
  113. '-framework', 'QuartzCore',
  114. '-framework', 'Security',
  115. '-framework', 'SystemConfiguration',
  116. '-framework', 'UIKit',
  117. ])
  118. # Feature options
  119. if env['game_center']:
  120. env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
  121. env.Append(LINKFLAGS=['-framework', 'GameKit'])
  122. if env['store_kit']:
  123. env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
  124. env.Append(LINKFLAGS=['-framework', 'StoreKit'])
  125. if env['icloud']:
  126. env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
  127. env.Append(CPPPATH=['$IPHONESDK/usr/include',
  128. '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers',
  129. '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers',
  130. ])
  131. env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
  132. env.Append(CPPPATH=['#platform/iphone'])
  133. env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DCOREAUDIO_ENABLED'])
  134. # TODO: Move that to opus module's config
  135. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  136. env.opus_fixed_point = "yes"
  137. if (env["arch"] == "arm"):
  138. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  139. elif (env["arch"] == "arm64"):
  140. env.Append(CFLAGS=["-DOPUS_ARM64_OPT"])