Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/ios/detect.py
11351 views
1
import os
2
import sys
3
from typing import TYPE_CHECKING
4
5
from methods import detect_darwin_sdk_path, detect_darwin_toolchain_path, print_error, print_warning
6
from platform_methods import validate_arch
7
8
if TYPE_CHECKING:
9
from SCons.Script.SConscript import SConsEnvironment
10
11
12
def get_name():
13
return "iOS"
14
15
16
def can_build():
17
if sys.platform == "darwin" or ("OSXCROSS_IOS" in os.environ):
18
return True
19
20
return False
21
22
23
def get_opts():
24
from SCons.Variables import BoolVariable
25
26
return [
27
("vulkan_sdk_path", "Path to the Vulkan SDK", ""),
28
# APPLE_TOOLCHAIN_PATH Example: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
29
(("APPLE_TOOLCHAIN_PATH", "IOS_TOOLCHAIN_PATH"), "Path to the Apple toolchain", ""),
30
(("APPLE_SDK_PATH", "IOS_SDK_PATH"), "Path to the iOS SDK", ""),
31
(("apple_target_triple", "ios_triple"), "Triple for the corresponding target Apple platform toolchain", ""),
32
BoolVariable(("simulator", "ios_simulator"), "Build for Simulator", False),
33
BoolVariable("generate_bundle", "Generate an APP bundle after building iOS/macOS binaries", False),
34
]
35
36
37
def get_doc_classes():
38
return [
39
"EditorExportPlatformIOS",
40
]
41
42
43
def get_doc_path():
44
return "doc_classes"
45
46
47
def get_flags():
48
return {
49
"arch": "arm64",
50
"target": "template_debug",
51
"use_volk": False,
52
"metal": True,
53
"supported": ["metal", "mono"],
54
"builtin_pcre2_with_jit": False,
55
}
56
57
58
def configure(env: "SConsEnvironment"):
59
# Validate arch.
60
supported_arches = ["x86_64", "arm64"]
61
validate_arch(env["arch"], get_name(), supported_arches)
62
detect_darwin_toolchain_path(env)
63
64
## LTO
65
66
if env["lto"] == "auto": # Disable by default as it makes linking in Xcode very slow.
67
env["lto"] = "none"
68
69
if env["lto"] != "none":
70
if env["lto"] == "thin":
71
env.Append(CCFLAGS=["-flto=thin"])
72
env.Append(LINKFLAGS=["-flto=thin"])
73
else:
74
env.Append(CCFLAGS=["-flto"])
75
env.Append(LINKFLAGS=["-flto"])
76
77
## Compiler configuration
78
79
# Save this in environment for use by other modules
80
if "OSXCROSS_IOS" in os.environ:
81
env["osxcross"] = True
82
83
env["ENV"]["PATH"] = env["APPLE_TOOLCHAIN_PATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
84
85
compiler_path = "$APPLE_TOOLCHAIN_PATH/usr/bin/${apple_target_triple}"
86
87
ccache_path = os.environ.get("CCACHE")
88
if ccache_path is None:
89
env["CC"] = compiler_path + "clang"
90
env["CXX"] = compiler_path + "clang++"
91
env["S_compiler"] = compiler_path + "clang"
92
else:
93
# there aren't any ccache wrappers available for iOS,
94
# to enable caching we need to prepend the path to the ccache binary
95
env["CC"] = ccache_path + " " + compiler_path + "clang"
96
env["CXX"] = ccache_path + " " + compiler_path + "clang++"
97
env["S_compiler"] = ccache_path + " " + compiler_path + "clang"
98
env["AR"] = compiler_path + "ar"
99
env["RANLIB"] = compiler_path + "ranlib"
100
101
## Compile flags
102
103
if env["simulator"]:
104
env["APPLE_PLATFORM"] = "iossimulator"
105
env.Append(ASFLAGS=["-mios-simulator-version-min=14.0"])
106
env.Append(CCFLAGS=["-mios-simulator-version-min=14.0"])
107
env.Append(CPPDEFINES=["IOS_SIMULATOR"])
108
env.extra_suffix = ".simulator" + env.extra_suffix
109
else:
110
env["APPLE_PLATFORM"] = "ios"
111
env.Append(ASFLAGS=["-miphoneos-version-min=14.0"])
112
env.Append(CCFLAGS=["-miphoneos-version-min=14.0"])
113
detect_darwin_sdk_path(env["APPLE_PLATFORM"], env)
114
115
if env["arch"] == "x86_64":
116
if not env["simulator"]:
117
print_error("Building for iOS with 'arch=x86_64' requires 'simulator=yes'.")
118
sys.exit(255)
119
120
env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
121
env.Append(
122
CCFLAGS=(
123
"-fobjc-arc -arch x86_64"
124
" -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks"
125
" -fasm-blocks -isysroot $APPLE_SDK_PATH"
126
).split()
127
)
128
env.Append(ASFLAGS=["-arch", "x86_64"])
129
elif env["arch"] == "arm64":
130
env.Append(
131
CCFLAGS=(
132
"-fobjc-arc -arch arm64 -fmessage-length=0"
133
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
134
" -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies"
135
" -isysroot $APPLE_SDK_PATH".split()
136
)
137
)
138
env.Append(ASFLAGS=["-arch", "arm64"])
139
140
# Temp fix for ABS/MAX/MIN macros in iOS SDK blocking compilation
141
env.Append(CCFLAGS=["-Wno-ambiguous-macro"])
142
143
env.Prepend(
144
CPPPATH=[
145
"$APPLE_SDK_PATH/usr/include",
146
"$APPLE_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers",
147
]
148
)
149
150
env.Prepend(CPPPATH=["#platform/ios"])
151
env.Append(CPPDEFINES=["IOS_ENABLED", "APPLE_EMBEDDED_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])
152
153
if env["metal"] and env["simulator"]:
154
print_warning("iOS Simulator does not support the Metal rendering driver")
155
env["metal"] = False
156
157
if env["metal"]:
158
env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"])
159
env.Prepend(
160
CPPPATH=[
161
"$APPLE_SDK_PATH/System/Library/Frameworks/Metal.framework/Headers",
162
"$APPLE_SDK_PATH/System/Library/Frameworks/MetalFX.framework/Headers",
163
"$APPLE_SDK_PATH/System/Library/Frameworks/QuartzCore.framework/Headers",
164
]
165
)
166
env.Prepend(CPPEXTPATH=["#thirdparty/spirv-cross"])
167
168
if env["vulkan"] and env["simulator"]:
169
print_warning("iOS Simulator does not support the Vulkan rendering driver")
170
env["vulkan"] = False
171
172
if env["vulkan"]:
173
env.AppendUnique(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"])
174
175
if env["opengl3"]:
176
env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"])
177
env.Append(CCFLAGS=["-Wno-module-import-in-extern-c"])
178
env.Prepend(
179
CPPPATH=[
180
"$APPLE_SDK_PATH/System/Library/Frameworks/OpenGLES.framework/Headers",
181
]
182
)
183
184