detect.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. (
  16. "IPHONEPATH",
  17. "Path to iPhone toolchain",
  18. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
  19. ),
  20. ("IPHONESDK", "Path to the iPhone SDK", ""),
  21. BoolVariable("game_center", "Support for game center", True),
  22. BoolVariable("store_kit", "Support for in-app store", True),
  23. BoolVariable("icloud", "Support for iCloud", True),
  24. BoolVariable("ios_exceptions", "Enable exceptions", False),
  25. ("ios_triple", "Triple for ios toolchain", ""),
  26. ]
  27. def get_flags():
  28. return [
  29. ("tools", False),
  30. ]
  31. def configure(env):
  32. ## Build type
  33. if env["target"].startswith("release"):
  34. env.Append(CPPDEFINES=["NDEBUG", ("NS_BLOCK_ASSERTIONS", 1)])
  35. if env["optimize"] == "speed": # optimize for speed (default)
  36. env.Append(CCFLAGS=["-O2", "-ftree-vectorize", "-fomit-frame-pointer"])
  37. env.Append(LINKFLAGS=["-O2"])
  38. else: # optimize for size
  39. env.Append(CCFLAGS=["-Os", "-ftree-vectorize"])
  40. env.Append(LINKFLAGS=["-Os"])
  41. if env["target"] == "release_debug":
  42. env.Append(CPPDEFINES=["DEBUG_ENABLED"])
  43. elif env["target"] == "debug":
  44. env.Append(CCFLAGS=["-gdwarf-2", "-O0"])
  45. env.Append(CPPDEFINES=["_DEBUG", ("DEBUG", 1), "DEBUG_ENABLED"])
  46. if env["use_lto"]:
  47. env.Append(CCFLAGS=["-flto"])
  48. env.Append(LINKFLAGS=["-flto"])
  49. ## Architecture
  50. if env["arch"] == "x86": # i386
  51. env["bits"] = "32"
  52. elif env["arch"] == "x86_64":
  53. env["bits"] = "64"
  54. elif env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32": # arm
  55. env["arch"] = "arm"
  56. env["bits"] = "32"
  57. else: # armv64
  58. env["arch"] = "arm64"
  59. env["bits"] = "64"
  60. ## Compiler configuration
  61. # Save this in environment for use by other modules
  62. if "OSXCROSS_IOS" in os.environ:
  63. env["osxcross"] = True
  64. env["ENV"]["PATH"] = env["IPHONEPATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
  65. compiler_path = "$IPHONEPATH/usr/bin/${ios_triple}"
  66. s_compiler_path = "$IPHONEPATH/Developer/usr/bin/"
  67. ccache_path = os.environ.get("CCACHE")
  68. if ccache_path is None:
  69. env["CC"] = compiler_path + "clang"
  70. env["CXX"] = compiler_path + "clang++"
  71. env["S_compiler"] = s_compiler_path + "gcc"
  72. else:
  73. # there aren't any ccache wrappers available for iOS,
  74. # to enable caching we need to prepend the path to the ccache binary
  75. env["CC"] = ccache_path + " " + compiler_path + "clang"
  76. env["CXX"] = ccache_path + " " + compiler_path + "clang++"
  77. env["S_compiler"] = ccache_path + " " + s_compiler_path + "gcc"
  78. env["AR"] = compiler_path + "ar"
  79. env["RANLIB"] = compiler_path + "ranlib"
  80. ## Compile flags
  81. if env["arch"] == "x86" or env["arch"] == "x86_64":
  82. detect_darwin_sdk_path("iphonesimulator", env)
  83. env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
  84. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  85. env.Append(
  86. CCFLAGS=(
  87. "-arch "
  88. + arch_flag
  89. + " -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -isysroot $IPHONESDK -mios-simulator-version-min=10.0"
  90. ).split()
  91. )
  92. elif env["arch"] == "arm":
  93. detect_darwin_sdk_path("iphone", env)
  94. env.Append(
  95. 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()
  96. )
  97. elif env["arch"] == "arm64":
  98. detect_darwin_sdk_path("iphone", env)
  99. env.Append(
  100. 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()
  101. )
  102. env.Append(CPPDEFINES=["NEED_LONG_INT"])
  103. env.Append(CPPDEFINES=["LIBYUV_DISABLE_NEON"])
  104. # Disable exceptions on non-tools (template) builds
  105. if not env["tools"]:
  106. if env["ios_exceptions"]:
  107. env.Append(CCFLAGS=["-fexceptions"])
  108. else:
  109. env.Append(CCFLAGS=["-fno-exceptions"])
  110. ## Link flags
  111. if env["arch"] == "x86" or env["arch"] == "x86_64":
  112. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  113. env.Append(
  114. LINKFLAGS=[
  115. "-arch",
  116. arch_flag,
  117. "-mios-simulator-version-min=10.0",
  118. "-isysroot",
  119. "$IPHONESDK",
  120. "-Xlinker",
  121. "-objc_abi_version",
  122. "-Xlinker",
  123. "2",
  124. "-F$IPHONESDK",
  125. ]
  126. )
  127. elif env["arch"] == "arm":
  128. env.Append(LINKFLAGS=["-arch", "armv7", "-Wl,-dead_strip", "-miphoneos-version-min=10.0"])
  129. if env["arch"] == "arm64":
  130. env.Append(LINKFLAGS=["-arch", "arm64", "-Wl,-dead_strip", "-miphoneos-version-min=10.0"])
  131. env.Append(
  132. LINKFLAGS=[
  133. "-isysroot",
  134. "$IPHONESDK",
  135. "-framework",
  136. "AudioToolbox",
  137. "-framework",
  138. "AVFoundation",
  139. "-framework",
  140. "CoreAudio",
  141. "-framework",
  142. "CoreGraphics",
  143. "-framework",
  144. "CoreMedia",
  145. "-framework",
  146. "CoreVideo",
  147. "-framework",
  148. "CoreMotion",
  149. "-framework",
  150. "Foundation",
  151. "-framework",
  152. "GameController",
  153. "-framework",
  154. "MediaPlayer",
  155. "-framework",
  156. "OpenGLES",
  157. "-framework",
  158. "QuartzCore",
  159. "-framework",
  160. "Security",
  161. "-framework",
  162. "SystemConfiguration",
  163. "-framework",
  164. "UIKit",
  165. "-framework",
  166. "ARKit",
  167. ]
  168. )
  169. # Feature options
  170. if env["game_center"]:
  171. env.Append(CPPDEFINES=["GAME_CENTER_ENABLED"])
  172. env.Append(LINKFLAGS=["-framework", "GameKit"])
  173. if env["store_kit"]:
  174. env.Append(CPPDEFINES=["STOREKIT_ENABLED"])
  175. env.Append(LINKFLAGS=["-framework", "StoreKit"])
  176. if env["icloud"]:
  177. env.Append(CPPDEFINES=["ICLOUD_ENABLED"])
  178. env.Prepend(
  179. CPPPATH=[
  180. "$IPHONESDK/usr/include",
  181. "$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers",
  182. "$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers",
  183. ]
  184. )
  185. env["ENV"]["CODESIGN_ALLOCATE"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate"
  186. env.Prepend(CPPPATH=["#platform/iphone"])
  187. env.Append(CPPDEFINES=["IPHONE_ENABLED", "UNIX_ENABLED", "GLES_ENABLED", "COREAUDIO_ENABLED"])