From 8dbfe03d17cea8d726e8144ba0d1d456842dad28 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 6 Jun 2022 16:17:43 +0200 Subject: [PATCH] [SCons] Add OSXCross tool. --- tools/osx.py | 7 ++++++- tools/osxcross.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tools/osxcross.py diff --git a/tools/osx.py b/tools/osx.py index 1130f83..b709472 100644 --- a/tools/osx.py +++ b/tools/osx.py @@ -1,14 +1,16 @@ import os import sys +import osxcross def options(opts): opts.Add("macos_deployment_target", "macOS deployment target", "default") opts.Add("macos_sdk_path", "macOS SDK path", "") + osxcross.options(opts) def exists(env): - return sys.platform == "darwin" + return sys.platform == "darwin" or osxcross.exists(env) def generate(env): @@ -20,6 +22,9 @@ def generate(env): # Use clang on macOS by default env["CXX"] = "clang++" env["CC"] = "clang" + else: + # Use osxcross + osxcross.generate(env) if env["arch"] == "universal": env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) diff --git a/tools/osxcross.py b/tools/osxcross.py new file mode 100644 index 0000000..f11166d --- /dev/null +++ b/tools/osxcross.py @@ -0,0 +1,28 @@ +import os + + +def options(opts): + opts.Add("osxcross_sdk", "OSXCross SDK version", "darwin16") + + +def exists(env): + return "OSXCROSS_ROOT" in os.environ + + +def generate(env): + root = os.environ.get("OSXCROSS_ROOT", "") + if env["arch"] == "arm64": + basecmd = root + "/target/bin/arm64-apple-" + env["osxcross_sdk"] + "-" + else: + basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-" + + env["CC"] = basecmd + "clang" + env["CXX"] = basecmd + "clang++" + env["AR"] = basecmd + "ar" + env["RANLIB"] = basecmd + "ranlib" + env["AS"] = basecmd + "as" + + binpath = os.path.join(root, "target", "bin") + if binpath not in env["ENV"]["PATH"]: + # Add OSXCROSS bin folder to PATH (required for linking). + env["ENV"]["PATH"] = "%s:%s" % (binpath, env["ENV"]["PATH"])