Skip to content

Commit

Permalink
Merge pull request #39943 from bruvzg/macos_apple_silicon_3
Browse files Browse the repository at this point in the history
[macOS, 3.2] Add support for the Apple Silicon (ARM64) build target.
  • Loading branch information
akien-mga authored Jun 29, 2020
2 parents e88dc5d + 43888eb commit b833296
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 18 deletions.
10 changes: 8 additions & 2 deletions misc/dist/osx_template.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@
<string>$camera_usage_description</string>
<key>NSHumanReadableCopyright</key>
<string>$copyright</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
<string>10.9</string>
<key>LSMinimumSystemVersionByArchitecture</key>
<dict>
<key>x86_64</key>
<string>10.9.0</string>
<string>10.9</string>
</dict>
<key>NSHighResolutionCapable</key>
$highres
Expand Down
12 changes: 9 additions & 3 deletions misc/dist/osx_tools.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@
<key>NSCameraUsageDescription</key>
<string>Camera access is required to capture video.</string>
<key>NSRequiresAquaSystemAppearance</key>
<false />
<false />
<key>NSHumanReadableCopyright</key>
<string>© 2007-2020 Juan Linietsky, Ariel Manzur &amp; Godot Engine contributors</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
<string>10.9</string>
<key>LSMinimumSystemVersionByArchitecture</key>
<dict>
<key>x86_64</key>
<string>10.9.0</string>
<string>10.9</string>
</dict>
<key>NSHighResolutionCapable</key>
<true/>
Expand Down
5 changes: 5 additions & 0 deletions modules/camera/camera_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ - (void)dealloc {
// CameraOSX - Subclass for our camera server on OSX

void CameraOSX::update_feeds() {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeExternalUnknown, AVCaptureDeviceTypeBuiltInWideAngleCamera, nil] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];
NSArray *devices = session.devices;
#else
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
#endif

// remove devices that are gone..
for (int i = feeds.size() - 1; i >= 0; i--) {
Expand Down
3 changes: 3 additions & 0 deletions modules/opus/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ if env["builtin_opus"]:
env_opus.Append(CPPDEFINES=["OPUS_ARM_OPT"])
elif "arch" in env and env["arch"] == "arm64":
env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"])
elif env["platform"] == "osx":
if "arch" in env and env["arch"] == "arm64":
env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"])

env_thirdparty = env_opus.Clone()
env_thirdparty.disable_warnings()
Expand Down
4 changes: 3 additions & 1 deletion modules/webm/libvpx/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ else:
is_x11_or_server_arm = (env["platform"] == "x11" or env["platform"] == "server") and (
platform.machine().startswith("arm") or platform.machine().startswith("aarch")
)
is_macos_x86 = env["platform"] == "osx" and ("arch" in env and (env["arch"] != "arm64"))
is_ios_x86 = env["platform"] == "iphone" and ("arch" in env and env["arch"].startswith("x86"))
is_android_x86 = env["platform"] == "android" and env["android_arch"].startswith("x86")
if is_android_x86:
Expand All @@ -240,14 +241,15 @@ else:
and (
env["platform"] == "windows"
or env["platform"] == "x11"
or env["platform"] == "osx"
or env["platform"] == "haiku"
or is_macos_x86
or is_android_x86
or is_ios_x86
)
)
webm_cpu_arm = (
is_x11_or_server_arm
or (not is_macos_x86 and env["platform"] == "osx")
or (not is_ios_x86 and env["platform"] == "iphone")
or (not is_android_x86 and env["platform"] == "android")
)
Expand Down
18 changes: 12 additions & 6 deletions platform/osx/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ def configure(env):
env["osxcross"] = True

if not "osxcross" in env: # regular native build
env.Append(CCFLAGS=["-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
if env["arch"] == "arm64":
print("Building for macOS 10.15+, platform arm64.")
env.Append(CCFLAGS=["-arch", "arm64", "-mmacosx-version-min=10.15", "-target", "arm64-apple-macos10.15"])
env.Append(LINKFLAGS=["-arch", "arm64", "-mmacosx-version-min=10.15", "-target", "arm64-apple-macos10.15"])
else:
print("Building for macOS 10.9+, platform x86-64.")
env.Append(CCFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.9"])
env.Append(LINKFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.9"])

if env["macports_clang"] != "no":
mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
mpclangver = env["macports_clang"]
Expand Down Expand Up @@ -142,7 +149,8 @@ def configure(env):
## Dependencies

if env["builtin_libtheora"]:
env["x86_libtheora_opt_gcc"] = True
if env["arch"] != "arm64":
env["x86_libtheora_opt_gcc"] = True

## Flags

Expand All @@ -155,6 +163,7 @@ def configure(env):
"APPLE_STYLE_KEYS",
"COREAUDIO_ENABLED",
"COREMIDI_ENABLED",
"GL_SILENCE_DEPRECATION",
]
)
env.Append(
Expand Down Expand Up @@ -187,6 +196,3 @@ def configure(env):
]
)
env.Append(LIBS=["pthread"])

env.Append(CCFLAGS=["-mmacosx-version-min=10.9"])
env.Append(LINKFLAGS=["-mmacosx-version-min=10.9"])
24 changes: 18 additions & 6 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {

@end

@interface GodotContentView : NSView <NSTextInputClient> {
@interface GodotContentView : NSOpenGLView <NSTextInputClient> {
NSTrackingArea *trackingArea;
NSMutableAttributedString *markedText;
bool imeInputEventInProgress;
Expand Down Expand Up @@ -475,7 +475,11 @@ - (id)init {
trackingArea = nil;
imeInputEventInProgress = false;
[self updateTrackingAreas];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
[self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]];
#else
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
#endif
markedText = [[NSMutableAttributedString alloc] init];
return self;
}
Expand Down Expand Up @@ -619,11 +623,19 @@ - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {

NSPasteboard *pboard = [sender draggingPasteboard];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
NSArray<NSURL *> *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL];
#else
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
#endif

Vector<String> files;
for (NSUInteger i = 0; i < filenames.count; i++) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
NSString *ns = [[filenames objectAtIndex:i] path];
#else
NSString *ns = [filenames objectAtIndex:i];
#endif
char *utfs = strdup([ns UTF8String]);
String ret;
ret.parse_utf8(utfs);
Expand Down Expand Up @@ -712,7 +724,7 @@ - (void)mouseMoved:(NSEvent *)event {
const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor);
mm->set_position(pos);
mm->set_pressure([event pressure]);
if ([event subtype] == NSTabletPointEventSubtype) {
if ([event subtype] == NSEventSubtypeTabletPoint) {
const NSPoint p = [event tilt];
mm->set_tilt(Vector2(p.x, p.y));
}
Expand Down Expand Up @@ -1600,7 +1612,7 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay

ERR_FAIL_COND_V(context == nil, ERR_UNAVAILABLE);

[context setView:window_view];
[window_view setOpenGLContext:context];

[context makeCurrentContext];

Expand Down Expand Up @@ -1800,7 +1812,7 @@ virtual void log_error(const char *p_function, const char *p_file, int p_line, c
[window addButtonWithTitle:@"OK"];
[window setMessageText:ns_title];
[window setInformativeText:ns_alert];
[window setAlertStyle:NSWarningAlertStyle];
[window setAlertStyle:NSAlertStyleWarning];

// Display it, then release
[window runModal];
Expand Down Expand Up @@ -2686,14 +2698,14 @@ static int get_screen_index(NSScreen *screen) {
[window_object setBackgroundColor:[NSColor clearColor]];
[window_object setOpaque:NO];
[window_object setHasShadow:NO];
[context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
[context setValues:&opacity forParameter:NSOpenGLContextParameterSurfaceOpacity];
layered_window = true;
} else {
GLint opacity = 1;
[window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]];
[window_object setOpaque:YES];
[window_object setHasShadow:YES];
[context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
[context setValues:&opacity forParameter:NSOpenGLContextParameterSurfaceOpacity];
layered_window = false;
}
[context update];
Expand Down

0 comments on commit b833296

Please sign in to comment.