detect.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import os
  2. import string
  3. import sys
  4. from methods import detect_darwin_sdk_path
  5. def is_active():
  6. return True
  7. def get_name():
  8. return "iOS"
  9. def can_build():
  10. if sys.platform == 'darwin' or ("OSXCROSS_IOS" in os.environ):
  11. return True
  12. return False
  13. def get_opts():
  14. from SCons.Variables import BoolVariable
  15. return [
  16. ('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
  17. ('IPHONESDK', 'Path to the iPhone 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. ]
  24. def get_flags():
  25. return [
  26. ('tools', False),
  27. ]
  28. def configure(env):
  29. ## Build type
  30. if (env["target"].startswith("release")):
  31. env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1'])
  32. if (env["optimize"] == "speed"): #optimize for speed (default)
  33. env.Append(CPPFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations'])
  34. env.Append(LINKFLAGS=['-O2'])
  35. else: #optimize for size
  36. env.Append(CPPFLAGS=['-Os', '-ftree-vectorize'])
  37. env.Append(LINKFLAGS=['-Os'])
  38. if env["target"] == "release_debug":
  39. env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
  40. elif (env["target"] == "debug"):
  41. env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  42. if (env["use_lto"]):
  43. env.Append(CPPFLAGS=['-flto'])
  44. env.Append(LINKFLAGS=['-flto'])
  45. ## Architecture
  46. if env["arch"] == "x86": # i386
  47. env["bits"] = "32"
  48. elif env["arch"] == "x86_64":
  49. env["bits"] = "64"
  50. elif (env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32"): # arm
  51. env["arch"] = "arm"
  52. env["bits"] = "32"
  53. else: # armv64
  54. env["arch"] = "arm64"
  55. env["bits"] = "64"
  56. ## Compiler configuration
  57. # Save this in environment for use by other modules
  58. if "OSXCROSS_IOS" in os.environ:
  59. env["osxcross"] = True
  60. env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
  61. compiler_path = '$IPHONEPATH/usr/bin/${ios_triple}'
  62. s_compiler_path = '$IPHONEPATH/Developer/usr/bin/'
  63. ccache_path = os.environ.get("CCACHE")
  64. if ccache_path is None:
  65. env['CC'] = compiler_path + 'clang'
  66. env['CXX'] = compiler_path + 'clang++'
  67. env['S_compiler'] = s_compiler_path + 'gcc'
  68. else:
  69. # there aren't any ccache wrappers available for iOS,
  70. # to enable caching we need to prepend the path to the ccache binary
  71. env['CC'] = ccache_path + ' ' + compiler_path + 'clang'
  72. env['CXX'] = ccache_path + ' ' + compiler_path + 'clang++'
  73. env['S_compiler'] = ccache_path + ' ' + s_compiler_path + 'gcc'
  74. env['AR'] = compiler_path + 'ar'
  75. env['RANLIB'] = compiler_path + 'ranlib'
  76. ## Compile flags
  77. if (env["arch"] == "x86" or env["arch"] == "x86_64"):
  78. detect_darwin_sdk_path('iphonesimulator', env)
  79. env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
  80. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  81. 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=10.0 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"').split())
  82. elif (env["arch"] == "arm"):
  83. detect_darwin_sdk_path('iphone', env)
  84. 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=10.0 -MMD -MT dependencies'.split())
  85. elif (env["arch"] == "arm64"):
  86. detect_darwin_sdk_path('iphone', env)
  87. 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=10.0 -isysroot $IPHONESDK'.split())
  88. env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
  89. env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
  90. if env['ios_exceptions']:
  91. env.Append(CPPFLAGS=['-fexceptions'])
  92. else:
  93. env.Append(CPPFLAGS=['-fno-exceptions'])
  94. ## Link flags
  95. if (env["arch"] == "x86" or env["arch"] == "x86_64"):
  96. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  97. env.Append(LINKFLAGS=['-arch', arch_flag, '-mios-simulator-version-min=10.0',
  98. '-isysroot', '$IPHONESDK',
  99. '-Xlinker',
  100. '-objc_abi_version',
  101. '-Xlinker', '2',
  102. '-F$IPHONESDK',
  103. ])
  104. elif (env["arch"] == "arm"):
  105. env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=10.0'])
  106. if (env["arch"] == "arm64"):
  107. env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=10.0'])
  108. env.Append(LINKFLAGS=['-isysroot', '$IPHONESDK',
  109. '-framework', 'AudioToolbox',
  110. '-framework', 'AVFoundation',
  111. '-framework', 'CoreAudio',
  112. '-framework', 'CoreGraphics',
  113. '-framework', 'CoreMedia',
  114. '-framework', 'CoreMotion',
  115. '-framework', 'Foundation',
  116. '-framework', 'GameController',
  117. '-framework', 'MediaPlayer',
  118. '-framework', 'OpenGLES',
  119. '-framework', 'QuartzCore',
  120. '-framework', 'Security',
  121. '-framework', 'SystemConfiguration',
  122. '-framework', 'UIKit',
  123. ])
  124. # Feature options
  125. if env['game_center']:
  126. env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
  127. env.Append(LINKFLAGS=['-framework', 'GameKit'])
  128. if env['store_kit']:
  129. env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
  130. env.Append(LINKFLAGS=['-framework', 'StoreKit'])
  131. if env['icloud']:
  132. env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
  133. env.Append(CPPPATH=['$IPHONESDK/usr/include',
  134. '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers',
  135. '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers',
  136. ])
  137. env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
  138. env.Append(CPPPATH=['#platform/iphone'])
  139. env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DMPC_FIXED_POINT', '-DCOREAUDIO_ENABLED'])
  140. # TODO: Move that to opus module's config
  141. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  142. env.opus_fixed_point = "yes"
  143. if (env["arch"] == "arm"):
  144. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  145. elif (env["arch"] == "arm64"):
  146. env.Append(CFLAGS=["-DOPUS_ARM64_OPT"])