ios.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import os
  2. import sys
  3. import subprocess
  4. from SCons.Variables import *
  5. if sys.version_info < (3,):
  6. def decode_utf8(x):
  7. return x
  8. else:
  9. import codecs
  10. def decode_utf8(x):
  11. return codecs.utf_8_decode(x)[0]
  12. def options(opts):
  13. opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
  14. opts.Add(
  15. "IPHONEPATH",
  16. "Path to iPhone toolchain",
  17. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
  18. )
  19. def exists(env):
  20. return sys.platform == "darwin"
  21. def generate(env):
  22. if env["arch"] not in ("universal", "arm64", "x86_64"):
  23. print("Only universal, arm64, and x86_64 are supported on iOS. Exiting.")
  24. Exit()
  25. if env["ios_simulator"]:
  26. sdk_name = "iphonesimulator"
  27. env.Append(CCFLAGS=["-mios-simulator-version-min=10.0"])
  28. else:
  29. sdk_name = "iphoneos"
  30. env.Append(CCFLAGS=["-miphoneos-version-min=10.0"])
  31. try:
  32. sdk_path = decode_utf8(subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-path"]).strip())
  33. except (subprocess.CalledProcessError, OSError):
  34. raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
  35. compiler_path = env["IPHONEPATH"] + "/usr/bin/"
  36. env["ENV"]["PATH"] = env["IPHONEPATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
  37. env["CC"] = compiler_path + "clang"
  38. env["CXX"] = compiler_path + "clang++"
  39. env["AR"] = compiler_path + "ar"
  40. env["RANLIB"] = compiler_path + "ranlib"
  41. env["SHLIBSUFFIX"] = ".dylib"
  42. if env["arch"] == "universal":
  43. if env["ios_simulator"]:
  44. env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
  45. env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
  46. else:
  47. env.Append(LINKFLAGS=["-arch", "arm64"])
  48. env.Append(CCFLAGS=["-arch", "arm64"])
  49. else:
  50. env.Append(LINKFLAGS=["-arch", env["arch"]])
  51. env.Append(CCFLAGS=["-arch", env["arch"]])
  52. env.Append(CCFLAGS=["-isysroot", sdk_path])
  53. env.Append(LINKFLAGS=["-isysroot", sdk_path, "-F" + sdk_path])
  54. if env["target"] == "debug":
  55. env.Append(CCFLAGS=["-Og", "-g"])
  56. elif env["target"] == "release":
  57. env.Append(CCFLAGS=["-O3"])