From b27017a5e3db1d6acf11d89f35adfe7de8bdb600 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 30 Jun 2020 19:33:12 +0100 Subject: [PATCH] macOS: Initial support for macOS 11 and arm64 --- docs/CMake API.md | 5 +++++ modules/juce_core/native/juce_mac_Files.mm | 15 +++++++++++++-- modules/juce_core/native/juce_mac_SystemStats.mm | 3 +-- modules/juce_core/native/juce_osx_ObjCHelpers.h | 5 ----- modules/juce_core/system/juce_PlatformDefs.h | 4 +++- modules/juce_core/system/juce_SystemStats.h | 2 ++ .../juce_events/native/juce_mac_MessageManager.mm | 6 +++++- .../native/juce_mac_NSViewComponentPeer.mm | 9 +++++++-- 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/docs/CMake API.md b/docs/CMake API.md index 6c7070da62..bd5de10be7 100644 --- a/docs/CMake API.md +++ b/docs/CMake API.md @@ -119,6 +119,11 @@ provisioning profiles, which is achieved by passing the `-allowProvisioningUpdat cmake --build build-ios --target -- -allowProvisioningUpdates +### Building universal binaries for macOS + +Building universal binaries that will run on both arm64 and x86_64 can be achieved by +configuring the CMake project with `"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"`. + ### A note about compile definitions Module options and plugin options that would previously have been set in the Projucer can be set on diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm index d264430798..7766283b72 100644 --- a/modules/juce_core/native/juce_mac_Files.mm +++ b/modules/juce_core/native/juce_mac_Files.mm @@ -425,13 +425,23 @@ bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& StringArray params; params.addTokens (parameters, true); - NSMutableDictionary* dict = [[NSMutableDictionary new] autorelease]; - NSMutableArray* paramArray = [[NSMutableArray new] autorelease]; for (int i = 0; i < params.size(); ++i) [paramArray addObject: juceStringToNS (params[i])]; + #if (defined MAC_OS_X_VERSION_10_15) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15 + auto config = [NSWorkspaceOpenConfiguration configuration]; + [config setCreatesNewApplicationInstance: YES]; + config.arguments = paramArray; + + [workspace openApplicationAtURL: filenameAsURL + configuration: config + completionHandler: nil]; + return true; + #else + NSMutableDictionary* dict = [[NSMutableDictionary new] autorelease]; + [dict setObject: paramArray forKey: nsStringLiteral ("NSWorkspaceLaunchConfigurationArguments")]; @@ -439,6 +449,7 @@ bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& options: NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance configuration: dict error: nil]; + #endif } if (file.exists()) diff --git a/modules/juce_core/native/juce_mac_SystemStats.mm b/modules/juce_core/native/juce_mac_SystemStats.mm index 02b39acfca..35ad6fb9db 100644 --- a/modules/juce_core/native/juce_mac_SystemStats.mm +++ b/modules/juce_core/native/juce_mac_SystemStats.mm @@ -137,9 +137,8 @@ SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() StringArray parts; parts.addTokens (getOSXVersion(), ".", StringRef()); - jassert (parts[0].getIntValue() == 10); const int major = parts[1].getIntValue(); - jassert (major > 2); + jassert ((parts[0].getIntValue() == 10 && major > 2) || parts[0].getIntValue() == 11); return (OperatingSystemType) (major + MacOSX_10_4 - 4); #endif diff --git a/modules/juce_core/native/juce_osx_ObjCHelpers.h b/modules/juce_core/native/juce_osx_ObjCHelpers.h index 407d263d04..d7169c010f 100644 --- a/modules/juce_core/native/juce_osx_ObjCHelpers.h +++ b/modules/juce_core/native/juce_osx_ObjCHelpers.h @@ -208,11 +208,6 @@ ReturnValue ObjCMsgSendSuper (struct objc_super* s, SEL sel, Params... params) // These hacks are a workaround for newer Xcode builds which by default prevent calls to these objc functions.. typedef id (*MsgSendSuperFn) (struct objc_super*, SEL, ...); inline MsgSendSuperFn getMsgSendSuperFn() noexcept { return (MsgSendSuperFn) (void*) objc_msgSendSuper; } - -#if ! JUCE_IOS -typedef double (*MsgSendFPRetFn) (id, SEL op, ...); -inline MsgSendFPRetFn getMsgSendFPRetFn() noexcept { return (MsgSendFPRetFn) (void*) objc_msgSend_fpret; } -#endif #endif //============================================================================== diff --git a/modules/juce_core/system/juce_PlatformDefs.h b/modules/juce_core/system/juce_PlatformDefs.h index 52db7c6d6a..0016abfb0b 100644 --- a/modules/juce_core/system/juce_PlatformDefs.h +++ b/modules/juce_core/system/juce_PlatformDefs.h @@ -66,12 +66,14 @@ namespace juce @see jassert() */ #define JUCE_BREAK_IN_DEBUGGER { ::kill (0, SIGTRAP); } +#elif JUCE_MAC && JUCE_CLANG && JUCE_ARM + #define JUCE_BREAK_IN_DEBUGGER { __builtin_debugtrap(); } #elif JUCE_MSVC #ifndef __INTEL_COMPILER #pragma intrinsic (__debugbreak) #endif #define JUCE_BREAK_IN_DEBUGGER { __debugbreak(); } -#elif JUCE_GCC || JUCE_MAC +#elif JUCE_INTEL && (JUCE_GCC || JUCE_MAC) #if JUCE_NO_INLINE_ASM #define JUCE_BREAK_IN_DEBUGGER { } #else diff --git a/modules/juce_core/system/juce_SystemStats.h b/modules/juce_core/system/juce_SystemStats.h index 90342c56ba..9568a693c5 100644 --- a/modules/juce_core/system/juce_SystemStats.h +++ b/modules/juce_core/system/juce_SystemStats.h @@ -63,6 +63,8 @@ public: MacOSX_10_12 = MacOSX | 12, MacOSX_10_13 = MacOSX | 13, MacOSX_10_14 = MacOSX | 14, + MacOSX_10_15 = MacOSX | 15, + MacOSX_11_0 = MacOSX | 16, Win2000 = Windows | 1, WinXP = Windows | 2, diff --git a/modules/juce_events/native/juce_mac_MessageManager.mm b/modules/juce_events/native/juce_mac_MessageManager.mm index 10bfcbc190..36352ab5ba 100644 --- a/modules/juce_events/native/juce_mac_MessageManager.mm +++ b/modules/juce_events/native/juce_mac_MessageManager.mm @@ -144,7 +144,11 @@ private: { if (notification.userInfo != nil) { - NSUserNotification* userNotification = [notification.userInfo objectForKey: nsStringLiteral ("NSApplicationLaunchUserNotificationKey")]; + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") + // NSUserNotification is deprecated from macOS 11, but there doesn't seem to be a + // replacement for NSApplicationLaunchUserNotificationKey returning a non-deprecated type + NSUserNotification* userNotification = notification.userInfo[NSApplicationLaunchUserNotificationKey]; + JUCE_END_IGNORE_WARNINGS_GCC_LIKE if (userNotification != nil && userNotification.userInfo != nil) didReceiveRemoteNotification (self, nil, [NSApplication sharedApplication], userNotification.userInfo); diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 7adb2a869a..cc6c72bc20 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -23,6 +23,11 @@ ============================================================================== */ +@interface NSEvent (DeviceDelta) +- (float)deviceDeltaX; +- (float)deviceDeltaY; +@end + //============================================================================== #if defined (MAC_OS_X_VERSION_10_8) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8) \ && USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_DRAW_ASYNC @@ -680,8 +685,8 @@ public: } else if ([ev respondsToSelector: @selector (deviceDeltaX)]) { - wheel.deltaX = checkDeviceDeltaReturnValue ((float) getMsgSendFPRetFn() (ev, @selector (deviceDeltaX))); - wheel.deltaY = checkDeviceDeltaReturnValue ((float) getMsgSendFPRetFn() (ev, @selector (deviceDeltaY))); + wheel.deltaX = checkDeviceDeltaReturnValue ([ev deviceDeltaX]); + wheel.deltaY = checkDeviceDeltaReturnValue ([ev deviceDeltaY]); } } @catch (...)