detect.py 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import os
  2. import sys
  3. def is_active():
  4. return True
  5. def get_name():
  6. return "iOS"
  7. def can_build():
  8. if sys.platform == 'darwin' or ("OSXCROSS_IOS" in os.environ):
  9. return True
  10. return False
  11. def get_opts():
  12. return [
  13. ('IPHONEPLATFORM', 'name of the iphone platform', 'iPhoneOS'),
  14. ('IPHONEPATH', 'the path to iphone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
  15. ('IPHONESDK', 'path to the iphone SDK', '/Applications/Xcode.app/Contents/Developer/Platforms/${IPHONEPLATFORM}.platform/Developer/SDKs/${IPHONEPLATFORM}.sdk/'),
  16. ('game_center', 'Support for game center', 'yes'),
  17. ('store_kit', 'Support for in-app store', 'yes'),
  18. ('icloud', 'Support for iCloud', 'yes'),
  19. ('ios_gles22_override', 'Force GLES2.0 on iOS', 'yes'),
  20. ('ios_exceptions', 'Enable exceptions', 'no'),
  21. ('ios_triple', 'Triple for ios toolchain', ''),
  22. ('ios_sim', 'Build simulator binary', 'no'),
  23. ('use_lto', 'Use link time optimization', 'no')
  24. ]
  25. def get_flags():
  26. return [
  27. ('tools', 'no'),
  28. ]
  29. def configure(env):
  30. env.Append(CPPPATH=['#platform/iphone'])
  31. env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
  32. compiler_path = '$IPHONEPATH/usr/bin/${ios_triple}'
  33. ccache_path = os.environ.get("CCACHE")
  34. if ccache_path == None:
  35. env['CC'] = compiler_path + 'clang'
  36. env['CXX'] = compiler_path + 'clang++'
  37. else:
  38. # there aren't any ccache wrappers available for iOS,
  39. # to enable caching we need to prepend the path to the ccache binary
  40. env['CC'] = ccache_path + ' ' + compiler_path + 'clang'
  41. env['CXX'] = ccache_path + ' ' + compiler_path + 'clang++'
  42. env['AR'] = compiler_path + 'ar'
  43. env['RANLIB'] = compiler_path + 'ranlib'
  44. import string
  45. if (env["ios_sim"] == "yes" or env["arch"] == "x86"): # i386, simulator
  46. env["arch"] = "x86"
  47. env["bits"] = "32"
  48. 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())
  49. elif (env["arch"] == "arm64"): # arm64
  50. env["bits"] = "64"
  51. 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=7.0 -isysroot $IPHONESDK'.split())
  52. env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
  53. env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
  54. else: # armv7
  55. env["arch"] = "arm"
  56. env["bits"] = "32"
  57. 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=7.0 -MMD -MT dependencies'.split())
  58. if (env["arch"] == "x86"):
  59. env['IPHONEPLATFORM'] = 'iPhoneSimulator'
  60. env.Append(LINKFLAGS=['-arch', 'i386', '-mios-simulator-version-min=4.3',
  61. '-isysroot', '$IPHONESDK',
  62. #'-mmacosx-version-min=10.6',
  63. '-Xlinker',
  64. '-objc_abi_version',
  65. '-Xlinker', '2',
  66. '-framework', 'AudioToolbox',
  67. '-framework', 'AVFoundation',
  68. '-framework', 'CoreAudio',
  69. '-framework', 'CoreGraphics',
  70. '-framework', 'CoreMedia',
  71. '-framework', 'CoreMotion',
  72. '-framework', 'Foundation',
  73. '-framework', 'Security',
  74. '-framework', 'UIKit',
  75. '-framework', 'MediaPlayer',
  76. '-framework', 'OpenGLES',
  77. '-framework', 'QuartzCore',
  78. '-framework', 'SystemConfiguration',
  79. '-framework', 'GameController',
  80. '-F$IPHONESDK',
  81. ])
  82. elif (env["arch"] == "arm64"):
  83. env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=7.0',
  84. '-isysroot', '$IPHONESDK',
  85. #'-stdlib=libc++',
  86. '-framework', 'Foundation',
  87. '-framework', 'UIKit',
  88. '-framework', 'CoreGraphics',
  89. '-framework', 'OpenGLES',
  90. '-framework', 'QuartzCore',
  91. '-framework', 'CoreAudio',
  92. '-framework', 'AudioToolbox',
  93. '-framework', 'SystemConfiguration',
  94. '-framework', 'Security',
  95. #'-framework', 'AdSupport',
  96. '-framework', 'MediaPlayer',
  97. '-framework', 'AVFoundation',
  98. '-framework', 'CoreMedia',
  99. '-framework', 'CoreMotion',
  100. '-framework', 'GameController',
  101. ])
  102. else:
  103. env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=7.0',
  104. '-isysroot', '$IPHONESDK',
  105. '-framework', 'Foundation',
  106. '-framework', 'UIKit',
  107. '-framework', 'CoreGraphics',
  108. '-framework', 'OpenGLES',
  109. '-framework', 'QuartzCore',
  110. '-framework', 'CoreAudio',
  111. '-framework', 'AudioToolbox',
  112. '-framework', 'SystemConfiguration',
  113. '-framework', 'Security',
  114. #'-framework', 'AdSupport',
  115. '-framework', 'MediaPlayer',
  116. '-framework', 'AVFoundation',
  117. '-framework', 'CoreMedia',
  118. '-framework', 'CoreMotion',
  119. '-framework', 'GameController',
  120. ])
  121. if env['game_center'] == 'yes':
  122. env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
  123. env.Append(LINKFLAGS=['-framework', 'GameKit'])
  124. if env['store_kit'] == 'yes':
  125. env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
  126. env.Append(LINKFLAGS=['-framework', 'StoreKit'])
  127. if env['icloud'] == 'yes':
  128. env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
  129. env.Append(CPPPATH=['$IPHONESDK/usr/include', '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers', '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers'])
  130. if (env["target"].startswith("release")):
  131. env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1'])
  132. env.Append(CPPFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations'])
  133. env.Append(LINKFLAGS=['-O2'])
  134. if env['use_lto'] == 'yes':
  135. env.Append(CPPFLAGS=['-flto'])
  136. env.Append(LINKFLAGS=['-flto'])
  137. if env["target"] == "release_debug":
  138. env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
  139. elif (env["target"] == "debug"):
  140. env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED'])
  141. env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ENABLED'])
  142. if (env["ios_sim"] == "yes"): # TODO: Check if needed?
  143. env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
  144. env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
  145. env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DMPC_FIXED_POINT'])
  146. # TODO: Move that to opus module's config
  147. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  148. env.opus_fixed_point = "yes"
  149. if env["arch"] == "x86":
  150. pass
  151. elif(env["arch"] == "arm64"):
  152. env.Append(CFLAGS=["-DOPUS_ARM64_OPT"])
  153. else:
  154. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  155. if env['ios_exceptions'] == 'yes':
  156. env.Append(CPPFLAGS=['-fexceptions'])
  157. else:
  158. env.Append(CPPFLAGS=['-fno-exceptions'])
  159. # env['neon_enabled']=True
  160. env['S_compiler'] = '$IPHONEPATH/Developer/usr/bin/gcc'
  161. import methods
  162. env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.gen.h', src_suffix='.glsl')})
  163. env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.gen.h', src_suffix='.glsl')})
  164. env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.gen.h', src_suffix='.glsl')})