2024-07-18 08:35:16 +00:00
|
|
|
import codecs
|
2022-06-06 13:09:32 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2024-06-24 17:20:55 +00:00
|
|
|
import sys
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
import common_compiler_flags
|
2024-06-24 17:20:55 +00:00
|
|
|
from SCons.Variables import BoolVariable
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
2023-07-23 20:41:55 +00:00
|
|
|
def has_ios_osxcross():
|
|
|
|
return "OSXCROSS_IOS" in os.environ
|
|
|
|
|
|
|
|
|
2022-06-06 13:09:32 +00:00
|
|
|
def options(opts):
|
|
|
|
opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
|
2023-11-21 07:39:53 +00:00
|
|
|
opts.Add("ios_min_version", "Target minimum iphoneos/iphonesimulator version", "12.0")
|
2022-06-06 13:09:32 +00:00
|
|
|
opts.Add(
|
2022-07-20 08:01:47 +00:00
|
|
|
"IOS_TOOLCHAIN_PATH",
|
|
|
|
"Path to iOS toolchain",
|
2022-06-06 13:09:32 +00:00
|
|
|
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
|
|
|
|
)
|
2022-07-20 08:01:47 +00:00
|
|
|
opts.Add("IOS_SDK_PATH", "Path to the iOS SDK", "")
|
2023-07-23 20:41:55 +00:00
|
|
|
|
|
|
|
if has_ios_osxcross():
|
|
|
|
opts.Add("ios_triple", "Triple for ios toolchain", "")
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
2023-07-23 20:41:55 +00:00
|
|
|
return sys.platform == "darwin" or has_ios_osxcross()
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
if env["arch"] not in ("universal", "arm64", "x86_64"):
|
2023-07-23 20:41:55 +00:00
|
|
|
raise ValueError("Only universal, arm64, and x86_64 are supported on iOS. Exiting.")
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
if env["ios_simulator"]:
|
|
|
|
sdk_name = "iphonesimulator"
|
2022-06-08 12:31:09 +00:00
|
|
|
env.Append(CCFLAGS=["-mios-simulator-version-min=" + env["ios_min_version"]])
|
2022-06-06 13:09:32 +00:00
|
|
|
else:
|
|
|
|
sdk_name = "iphoneos"
|
2022-06-08 12:31:09 +00:00
|
|
|
env.Append(CCFLAGS=["-miphoneos-version-min=" + env["ios_min_version"]])
|
|
|
|
|
|
|
|
if sys.platform == "darwin":
|
2022-07-20 08:01:47 +00:00
|
|
|
if env["IOS_SDK_PATH"] == "":
|
2022-06-08 12:31:09 +00:00
|
|
|
try:
|
2024-07-18 08:35:16 +00:00
|
|
|
env["IOS_SDK_PATH"] = codecs.utf_8_decode(
|
2022-06-08 12:31:09 +00:00
|
|
|
subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-path"]).strip()
|
2024-07-18 08:35:16 +00:00
|
|
|
)[0]
|
2022-06-08 12:31:09 +00:00
|
|
|
except (subprocess.CalledProcessError, OSError):
|
|
|
|
raise ValueError(
|
|
|
|
"Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name)
|
|
|
|
)
|
|
|
|
|
2022-07-20 08:01:47 +00:00
|
|
|
compiler_path = env["IOS_TOOLCHAIN_PATH"] + "/usr/bin/"
|
2022-06-08 12:31:09 +00:00
|
|
|
env["CC"] = compiler_path + "clang"
|
|
|
|
env["CXX"] = compiler_path + "clang++"
|
|
|
|
env["AR"] = compiler_path + "ar"
|
|
|
|
env["RANLIB"] = compiler_path + "ranlib"
|
|
|
|
env["SHLIBSUFFIX"] = ".dylib"
|
2022-07-20 08:01:47 +00:00
|
|
|
env["ENV"]["PATH"] = env["IOS_TOOLCHAIN_PATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2022-06-08 12:31:09 +00:00
|
|
|
else:
|
2023-07-23 20:41:55 +00:00
|
|
|
# OSXCross
|
|
|
|
compiler_path = "$IOS_TOOLCHAIN_PATH/usr/bin/${ios_triple}"
|
|
|
|
env["CC"] = compiler_path + "clang"
|
|
|
|
env["CXX"] = compiler_path + "clang++"
|
|
|
|
env["AR"] = compiler_path + "ar"
|
|
|
|
env["RANLIB"] = compiler_path + "ranlib"
|
|
|
|
env["SHLIBSUFFIX"] = ".dylib"
|
|
|
|
|
|
|
|
env.Prepend(
|
|
|
|
CPPPATH=[
|
|
|
|
"$IOS_SDK_PATH/usr/include",
|
|
|
|
"$IOS_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
env.Append(CCFLAGS=["-stdlib=libc++"])
|
|
|
|
|
|
|
|
binpath = os.path.join(env["IOS_TOOLCHAIN_PATH"], "usr", "bin")
|
|
|
|
if binpath not in env["ENV"]["PATH"]:
|
|
|
|
env.PrependENVPath("PATH", binpath)
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
if env["arch"] == "universal":
|
|
|
|
if env["ios_simulator"]:
|
|
|
|
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", env["arch"]])
|
|
|
|
env.Append(CCFLAGS=["-arch", env["arch"]])
|
|
|
|
|
2022-07-20 08:01:47 +00:00
|
|
|
env.Append(CCFLAGS=["-isysroot", env["IOS_SDK_PATH"]])
|
|
|
|
env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]])
|
2023-07-22 12:46:14 +00:00
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED"])
|
2024-02-14 14:32:27 +00:00
|
|
|
|
|
|
|
common_compiler_flags.generate(env)
|