2
0

detect.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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(
  22. "use_static_mvk",
  23. "Link MoltenVK statically as Level-0 driver (better portability) or use Vulkan ICD loader (enables"
  24. " validation layers)",
  25. False,
  26. ),
  27. BoolVariable("ios_simulator", "Build for iOS Simulator", False),
  28. BoolVariable("ios_exceptions", "Enable exceptions", False),
  29. ("ios_triple", "Triple for ios toolchain", ""),
  30. ]
  31. def get_flags():
  32. return [
  33. ("tools", False),
  34. ]
  35. def configure(env):
  36. ## Build type
  37. if env["target"].startswith("release"):
  38. env.Append(CPPDEFINES=["NDEBUG", ("NS_BLOCK_ASSERTIONS", 1)])
  39. if env["optimize"] == "speed": # optimize for speed (default)
  40. env.Append(CCFLAGS=["-O2", "-ftree-vectorize", "-fomit-frame-pointer"])
  41. env.Append(LINKFLAGS=["-O2"])
  42. else: # optimize for size
  43. env.Append(CCFLAGS=["-Os", "-ftree-vectorize"])
  44. env.Append(LINKFLAGS=["-Os"])
  45. if env["target"] == "release_debug":
  46. env.Append(CPPDEFINES=["DEBUG_ENABLED"])
  47. elif env["target"] == "debug":
  48. env.Append(CCFLAGS=["-gdwarf-2", "-O0"])
  49. env.Append(CPPDEFINES=["_DEBUG", ("DEBUG", 1), "DEBUG_ENABLED"])
  50. if env["use_lto"]:
  51. env.Append(CCFLAGS=["-flto"])
  52. env.Append(LINKFLAGS=["-flto"])
  53. ## Architecture
  54. if env["arch"] == "x86": # i386
  55. env["bits"] = "32"
  56. elif env["arch"] == "x86_64":
  57. env["bits"] = "64"
  58. elif env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32": # arm
  59. env["arch"] = "arm"
  60. env["bits"] = "32"
  61. else: # armv64
  62. env["arch"] = "arm64"
  63. env["bits"] = "64"
  64. ## Compiler configuration
  65. # Save this in environment for use by other modules
  66. if "OSXCROSS_IOS" in os.environ:
  67. env["osxcross"] = True
  68. env["ENV"]["PATH"] = env["IPHONEPATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
  69. compiler_path = "$IPHONEPATH/usr/bin/${ios_triple}"
  70. s_compiler_path = "$IPHONEPATH/Developer/usr/bin/"
  71. ccache_path = os.environ.get("CCACHE")
  72. if ccache_path is None:
  73. env["CC"] = compiler_path + "clang"
  74. env["CXX"] = compiler_path + "clang++"
  75. env["S_compiler"] = s_compiler_path + "gcc"
  76. else:
  77. # there aren't any ccache wrappers available for iOS,
  78. # to enable caching we need to prepend the path to the ccache binary
  79. env["CC"] = ccache_path + " " + compiler_path + "clang"
  80. env["CXX"] = ccache_path + " " + compiler_path + "clang++"
  81. env["S_compiler"] = ccache_path + " " + s_compiler_path + "gcc"
  82. env["AR"] = compiler_path + "ar"
  83. env["RANLIB"] = compiler_path + "ranlib"
  84. ## Compile flags
  85. if env["ios_simulator"]:
  86. detect_darwin_sdk_path("iphonesimulator", env)
  87. env.Append(CCFLAGS=["-mios-simulator-version-min=13.0"])
  88. env.Append(LINKFLAGS=["-mios-simulator-version-min=13.0"])
  89. env.extra_suffix = ".simulator" + env.extra_suffix
  90. else:
  91. detect_darwin_sdk_path("iphone", env)
  92. env.Append(CCFLAGS=["-miphoneos-version-min=11.0"])
  93. env.Append(LINKFLAGS=["-miphoneos-version-min=11.0"])
  94. if env["arch"] == "x86" or env["arch"] == "x86_64":
  95. env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
  96. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  97. env.Append(
  98. CCFLAGS=(
  99. "-fobjc-arc -arch "
  100. + arch_flag
  101. + " -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks"
  102. " -fasm-blocks -isysroot $IPHONESDK"
  103. ).split()
  104. )
  105. elif env["arch"] == "arm":
  106. env.Append(
  107. CCFLAGS=(
  108. "-fobjc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing"
  109. " -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
  110. " -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb"
  111. ' "-DIBOutlet=__attribute__((iboutlet))"'
  112. ' "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))"'
  113. ' "-DIBAction=void)__attribute__((ibaction)" -MMD -MT dependencies'.split()
  114. )
  115. )
  116. elif env["arch"] == "arm64":
  117. env.Append(
  118. CCFLAGS=(
  119. "-fobjc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing"
  120. " -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
  121. " -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies"
  122. " -isysroot $IPHONESDK".split()
  123. )
  124. )
  125. env.Append(CPPDEFINES=["NEED_LONG_INT"])
  126. env.Append(CPPDEFINES=["LIBYUV_DISABLE_NEON"])
  127. # Disable exceptions on non-tools (template) builds
  128. if not env["tools"]:
  129. if env["ios_exceptions"]:
  130. env.Append(CCFLAGS=["-fexceptions"])
  131. else:
  132. env.Append(CCFLAGS=["-fno-exceptions"])
  133. # Temp fix for ABS/MAX/MIN macros in iPhone SDK blocking compilation
  134. env.Append(CCFLAGS=["-Wno-ambiguous-macro"])
  135. ## Link flags
  136. if env["arch"] == "x86" or env["arch"] == "x86_64":
  137. arch_flag = "i386" if env["arch"] == "x86" else env["arch"]
  138. env.Append(
  139. LINKFLAGS=[
  140. "-arch",
  141. arch_flag,
  142. "-isysroot",
  143. "$IPHONESDK",
  144. "-Xlinker",
  145. "-objc_abi_version",
  146. "-Xlinker",
  147. "2",
  148. "-F$IPHONESDK",
  149. ]
  150. )
  151. elif env["arch"] == "arm":
  152. env.Append(LINKFLAGS=["-arch", "armv7", "-Wl,-dead_strip"])
  153. if env["arch"] == "arm64":
  154. env.Append(LINKFLAGS=["-arch", "arm64", "-Wl,-dead_strip"])
  155. env.Append(
  156. LINKFLAGS=[
  157. "-isysroot",
  158. "$IPHONESDK",
  159. ]
  160. )
  161. env.Prepend(
  162. CPPPATH=[
  163. "$IPHONESDK/usr/include",
  164. "$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers",
  165. ]
  166. )
  167. env["ENV"]["CODESIGN_ALLOCATE"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate"
  168. env.Prepend(CPPPATH=["#platform/iphone"])
  169. env.Append(CPPDEFINES=["IPHONE_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])
  170. env.Append(CPPDEFINES=["VULKAN_ENABLED"])
  171. env.Append(LINKFLAGS=["-framework", "IOSurface"])
  172. # Use Static Vulkan for iOS. Dynamic Framework works fine too.
  173. env.Append(LINKFLAGS=["-framework", "MoltenVK"])
  174. env["builtin_vulkan"] = False