2
0

detect.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import os
  2. import sys
  3. from methods import detect_darwin_sdk_path
  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. ('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
  16. ('IPHONESDK', 'Path to the iPhone SDK', ''),
  17. BoolVariable('game_center', 'Support for game center', True),
  18. BoolVariable('store_kit', 'Support for in-app store', True),
  19. BoolVariable('icloud', 'Support for iCloud', True),
  20. BoolVariable('ios_exceptions', 'Enable exceptions', False),
  21. ('ios_triple', 'Triple for ios toolchain', ''),
  22. ]
  23. def get_flags():
  24. return [
  25. ('tools', False),
  26. ]
  27. def configure(env):
  28. ## Build type
  29. if (env["target"].startswith("release")):
  30. env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1'])
  31. if (env["optimize"] == "speed"): #optimize for speed (default)
  32. env.Append(CCFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer'])
  33. env.Append(LINKFLAGS=['-O2'])
  34. else: #optimize for size
  35. env.Append(CCFLAGS=['-Os', '-ftree-vectorize'])
  36. env.Append(LINKFLAGS=['-Os'])
  37. if env["target"] == "release_debug":
  38. env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
  39. elif (env["target"] == "debug"):
  40. env.Append(CCFLAGS=['-gdwarf-2', '-O0'])
  41. env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  42. if (env["use_lto"]):
  43. env.Append(CCFLAGS=['-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').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. # Disable exceptions on non-tools (template) builds
  91. if not env['tools']:
  92. if env['ios_exceptions']:
  93. env.Append(CCFLAGS=['-fexceptions'])
  94. else:
  95. env.Append(CCFLAGS=['-fno-exceptions'])
  96. ## Link flags
  97. if (env["arch"] == "x86" or env["arch"] == "x86_64"):
  98. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  99. env.Append(LINKFLAGS=['-arch', arch_flag, '-mios-simulator-version-min=10.0',
  100. '-isysroot', '$IPHONESDK',
  101. '-Xlinker',
  102. '-objc_abi_version',
  103. '-Xlinker', '2',
  104. '-F$IPHONESDK',
  105. ])
  106. elif (env["arch"] == "arm"):
  107. env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=10.0'])
  108. if (env["arch"] == "arm64"):
  109. env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=10.0'])
  110. env.Append(LINKFLAGS=['-isysroot', '$IPHONESDK',
  111. '-framework', 'AudioToolbox',
  112. '-framework', 'AVFoundation',
  113. '-framework', 'CoreAudio',
  114. '-framework', 'CoreGraphics',
  115. '-framework', 'CoreMedia',
  116. '-framework', 'CoreMotion',
  117. '-framework', 'Foundation',
  118. '-framework', 'GameController',
  119. '-framework', 'MediaPlayer',
  120. '-framework', 'OpenGLES',
  121. '-framework', 'QuartzCore',
  122. '-framework', 'Security',
  123. '-framework', 'SystemConfiguration',
  124. '-framework', 'UIKit',
  125. ])
  126. # Feature options
  127. if env['game_center']:
  128. env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED'])
  129. env.Append(LINKFLAGS=['-framework', 'GameKit'])
  130. if env['store_kit']:
  131. env.Append(CPPFLAGS=['-DSTOREKIT_ENABLED'])
  132. env.Append(LINKFLAGS=['-framework', 'StoreKit'])
  133. if env['icloud']:
  134. env.Append(CPPFLAGS=['-DICLOUD_ENABLED'])
  135. env.Prepend(CPPPATH=['$IPHONESDK/usr/include',
  136. '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers',
  137. '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers',
  138. ])
  139. env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
  140. env.Prepend(CPPPATH=['#platform/iphone'])
  141. env.Append(CPPFLAGS=['-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DCOREAUDIO_ENABLED'])