2
0

detect.py 5.6 KB

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