2022-06-06 13:09:32 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2024-06-24 17:20:55 +00:00
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
import common_compiler_flags
|
2023-07-23 20:41:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def has_osxcross():
|
|
|
|
return "OSXCROSS_ROOT" in os.environ
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def options(opts):
|
|
|
|
opts.Add("macos_deployment_target", "macOS deployment target", "default")
|
|
|
|
opts.Add("macos_sdk_path", "macOS SDK path", "")
|
2023-07-23 20:41:55 +00:00
|
|
|
if has_osxcross():
|
|
|
|
opts.Add("osxcross_sdk", "OSXCross SDK version", "darwin16")
|
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_osxcross()
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
if env["arch"] not in ("universal", "arm64", "x86_64"):
|
|
|
|
print("Only universal, arm64, and x86_64 are supported on macOS. Exiting.")
|
2023-09-09 08:55:53 +00:00
|
|
|
env.Exit(1)
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
# Use clang on macOS by default
|
|
|
|
env["CXX"] = "clang++"
|
|
|
|
env["CC"] = "clang"
|
2022-06-06 14:17:43 +00:00
|
|
|
else:
|
2023-07-23 20:41:55 +00:00
|
|
|
# OSXCross
|
|
|
|
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.PrependENVPath("PATH", binpath)
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-07-23 20:41:55 +00:00
|
|
|
# Common flags
|
2022-06-06 13:09:32 +00:00
|
|
|
if env["arch"] == "universal":
|
|
|
|
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", env["arch"]])
|
|
|
|
env.Append(CCFLAGS=["-arch", env["arch"]])
|
|
|
|
|
|
|
|
if env["macos_deployment_target"] != "default":
|
|
|
|
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
|
|
|
|
env.Append(LINKFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
|
|
|
|
|
|
|
|
if env["macos_sdk_path"]:
|
|
|
|
env.Append(CCFLAGS=["-isysroot", env["macos_sdk_path"]])
|
|
|
|
env.Append(LINKFLAGS=["-isysroot", env["macos_sdk_path"]])
|
|
|
|
|
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-framework",
|
|
|
|
"Cocoa",
|
|
|
|
"-Wl,-undefined,dynamic_lookup",
|
|
|
|
]
|
|
|
|
)
|
2023-07-22 12:46:14 +00:00
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["MACOS_ENABLED", "UNIX_ENABLED"])
|
2024-02-14 14:32:27 +00:00
|
|
|
|
2024-09-21 10:52:50 +00:00
|
|
|
# Refer to https://github.com/godotengine/godot/blob/master/platform/macos/detect.py
|
|
|
|
# LTO benefits for macOS (size, performance) haven't been clearly established yet.
|
|
|
|
if env["lto"] == "auto":
|
|
|
|
env["lto"] = "none"
|
|
|
|
|
2024-02-14 14:32:27 +00:00
|
|
|
common_compiler_flags.generate(env)
|