From cd19c9fa22358ab9648a7edcba0529b85b93f6c5 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 18 Sep 2016 17:22:39 -0700 Subject: [PATCH] Don't force compile everything as Objective-C++ on macOS --- CMakeLists.txt | 9 --- Source/Core/Common/CMakeLists.txt | 2 +- Source/Core/Common/GL/GLInterface/AGL.h | 5 +- .../Common/GL/GLInterface/{AGL.cpp => AGL.mm} | 0 Source/Core/Core/HW/WiimoteReal/IOdarwin.h | 66 ---------------- Source/Core/Core/HW/WiimoteReal/IOdarwin.mm | 1 + .../Core/HW/WiimoteReal/IOdarwin_private.h | 77 +++++++++++++++++++ Source/Core/DolphinWX/AboutDolphin.cpp | 4 - Source/Core/DolphinWX/Frame.cpp | 24 ------ Source/Core/DolphinWX/FrameTools.cpp | 14 +--- Source/Core/DolphinWX/ISOProperties.cpp | 12 +-- Source/Core/DolphinWX/Main.cpp | 4 - Source/Core/DolphinWX/WxUtils.cpp | 4 - 13 files changed, 89 insertions(+), 133 deletions(-) rename Source/Core/Common/GL/GLInterface/{AGL.cpp => AGL.mm} (100%) create mode 100644 Source/Core/Core/HW/WiimoteReal/IOdarwin_private.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 15e52bda7b..e8892b2695 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -984,15 +984,6 @@ add_definitions(-std=c++1y) # but some dependencies require them (LLVM, libav). add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS) -# Do this at the last minute because try_compile ignores linker flags. Yay... -if(APPLE) - # Some of our code contains Objective C constructs. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++") - # Avoid mistaking an object file for a source file on the link command line. - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none") -endif() - add_subdirectory(Source) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 5756952061..7da6a0a037 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -82,7 +82,7 @@ endif() if(WIN32) set(SRCS ${SRCS} GL/GLInterface/WGL.cpp) elseif(APPLE) - set(SRCS ${SRCS} GL/GLInterface/AGL.cpp) + set(SRCS ${SRCS} GL/GLInterface/AGL.mm) elseif(USE_X11) if (NOT USE_EGL) set(SRCS ${SRCS} GL/GLInterface/GLX.cpp) diff --git a/Source/Core/Common/GL/GLInterface/AGL.h b/Source/Core/Common/GL/GLInterface/AGL.h index d326b04499..fa5e872f41 100644 --- a/Source/Core/Common/GL/GLInterface/AGL.h +++ b/Source/Core/Common/GL/GLInterface/AGL.h @@ -4,8 +4,11 @@ #pragma once -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(__OBJC__) #import +#else +struct NSOpenGLContext; +struct NSView; #endif #include "Common/GL/GLInterfaceBase.h" diff --git a/Source/Core/Common/GL/GLInterface/AGL.cpp b/Source/Core/Common/GL/GLInterface/AGL.mm similarity index 100% rename from Source/Core/Common/GL/GLInterface/AGL.cpp rename to Source/Core/Common/GL/GLInterface/AGL.mm diff --git a/Source/Core/Core/HW/WiimoteReal/IOdarwin.h b/Source/Core/Core/HW/WiimoteReal/IOdarwin.h index 9d7a10bc6f..bf88d5ea24 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOdarwin.h +++ b/Source/Core/Core/HW/WiimoteReal/IOdarwin.h @@ -5,76 +5,10 @@ #pragma once #ifdef __APPLE__ -// Work around an Apple bug: for some reason, IOBluetooth.h errors on -// inclusion in Mavericks, but only in Objective-C++ C++11 mode. I filed -// this as ; in the meantime... -#import -#undef NS_ENUM_AVAILABLE -#define NS_ENUM_AVAILABLE(...) -// end hack -#import -#include -#include - #include "Core/HW/WiimoteReal/WiimoteReal.h" namespace WiimoteReal { -class WiimoteDarwin final : public Wiimote -{ -public: - WiimoteDarwin(IOBluetoothDevice* device); - ~WiimoteDarwin() override; - - // These are not protected/private because ConnectBT needs them. - void DisconnectInternal() override; - IOBluetoothDevice* m_btd; - unsigned char* m_input; - int m_inputlen; - -protected: - bool ConnectInternal() override; - bool IsConnected() const override; - void IOWakeup() override; - int IORead(u8* buf) override; - int IOWrite(u8 const* buf, size_t len) override; - void EnablePowerAssertionInternal() override; - void DisablePowerAssertionInternal() override; - -private: - IOBluetoothL2CAPChannel* m_ichan; - IOBluetoothL2CAPChannel* m_cchan; - bool m_connected; - CFRunLoopRef m_wiimote_thread_run_loop; - IOPMAssertionID m_pm_assertion; -}; - -class WiimoteDarwinHid final : public Wiimote -{ -public: - WiimoteDarwinHid(IOHIDDeviceRef device); - ~WiimoteDarwinHid() override; - -protected: - bool ConnectInternal() override; - void DisconnectInternal() override; - bool IsConnected() const override; - void IOWakeup() override; - int IORead(u8* buf) override; - int IOWrite(u8 const* buf, size_t len) override; - -private: - static void ReportCallback(void* context, IOReturn result, void* sender, IOHIDReportType type, - u32 reportID, u8* report, CFIndex reportLength); - static void RemoveCallback(void* context, IOReturn result, void* sender); - void QueueBufferReport(int length); - IOHIDDeviceRef m_device; - bool m_connected; - std::atomic m_interrupted; - Report m_report_buffer; - Common::FifoQueue m_buffered_reports; -}; - class WiimoteScannerDarwin final : public WiimoteScannerBackend { public: diff --git a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm index 0ce4b68dff..6b810227a0 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm @@ -4,6 +4,7 @@ #include "Common/Common.h" #include "Common/Logging/Log.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h" +#include "Core/HW/WiimoteReal/IOdarwin_private.h" @interface SearchBT : NSObject { diff --git a/Source/Core/Core/HW/WiimoteReal/IOdarwin_private.h b/Source/Core/Core/HW/WiimoteReal/IOdarwin_private.h new file mode 100644 index 0000000000..5ced0d708d --- /dev/null +++ b/Source/Core/Core/HW/WiimoteReal/IOdarwin_private.h @@ -0,0 +1,77 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include "Core/HW/WiimoteReal/WiimoteReal.h" + +// Work around an Apple bug: for some reason, IOBluetooth.h errors on +// inclusion in Mavericks, but only in Objective-C++ C++11 mode. I filed +// this as ; in the meantime... +#import +#undef NS_ENUM_AVAILABLE +#define NS_ENUM_AVAILABLE(...) +// end hack +#include +#include +#include + +namespace WiimoteReal +{ +class WiimoteDarwin final : public Wiimote +{ +public: + WiimoteDarwin(IOBluetoothDevice* device); + ~WiimoteDarwin() override; + + // These are not protected/private because ConnectBT needs them. + void DisconnectInternal() override; + IOBluetoothDevice* m_btd; + unsigned char* m_input; + int m_inputlen; + +protected: + bool ConnectInternal() override; + bool IsConnected() const override; + void IOWakeup() override; + int IORead(u8* buf) override; + int IOWrite(u8 const* buf, size_t len) override; + void EnablePowerAssertionInternal() override; + void DisablePowerAssertionInternal() override; + +private: + IOBluetoothL2CAPChannel* m_ichan; + IOBluetoothL2CAPChannel* m_cchan; + bool m_connected; + CFRunLoopRef m_wiimote_thread_run_loop; + IOPMAssertionID m_pm_assertion; +}; + +class WiimoteDarwinHid final : public Wiimote +{ +public: + WiimoteDarwinHid(IOHIDDeviceRef device); + ~WiimoteDarwinHid() override; + +protected: + bool ConnectInternal() override; + void DisconnectInternal() override; + bool IsConnected() const override; + void IOWakeup() override; + int IORead(u8* buf) override; + int IOWrite(u8 const* buf, size_t len) override; + +private: + static void ReportCallback(void* context, IOReturn result, void* sender, IOHIDReportType type, + u32 reportID, u8* report, CFIndex reportLength); + static void RemoveCallback(void* context, IOReturn result, void* sender); + void QueueBufferReport(int length); + IOHIDDeviceRef m_device; + bool m_connected; + std::atomic m_interrupted; + Report m_report_buffer; + Common::FifoQueue m_buffered_reports; +}; + +} // namespace WiimoteReal diff --git a/Source/Core/DolphinWX/AboutDolphin.cpp b/Source/Core/DolphinWX/AboutDolphin.cpp index ea3a8a10e8..90702ae34e 100644 --- a/Source/Core/DolphinWX/AboutDolphin.cpp +++ b/Source/Core/DolphinWX/AboutDolphin.cpp @@ -12,10 +12,6 @@ #include #include -#ifdef __APPLE__ -#import -#endif - #include "Common/Common.h" #include "DolphinWX/AboutDolphin.h" #include "DolphinWX/WxUtils.h" diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 5b0b8e1049..505fb67166 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -2,10 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#ifdef __APPLE__ -#include -#endif - #include #include #include @@ -584,16 +580,6 @@ bool CFrame::RendererIsFullscreen() fullscreen = m_RenderFrame->IsFullScreen(); } -#if defined(__APPLE__) - if (m_RenderFrame != nullptr) - { - NSView* view = (NSView*)m_RenderFrame->GetHandle(); - NSWindow* window = [view window]; - - fullscreen = (([window styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask); - } -#endif - return fullscreen; } @@ -1284,15 +1270,6 @@ void CFrame::DoFullscreen(bool enable_fullscreen) ToggleDisplayMode(enable_fullscreen); -#if defined(__APPLE__) - NSView* view = (NSView*)m_RenderFrame->GetHandle(); - NSWindow* window = [view window]; - - if (enable_fullscreen != RendererIsFullscreen()) - { - [window toggleFullScreen:nil]; - } -#else if (enable_fullscreen) { m_RenderFrame->ShowFullScreen(true, wxFULLSCREEN_ALL); @@ -1303,7 +1280,6 @@ void CFrame::DoFullscreen(bool enable_fullscreen) // Therefore we don't exit fullscreen from here if we are in exclusive mode. m_RenderFrame->ShowFullScreen(false, wxFULLSCREEN_ALL); } -#endif if (SConfig::GetInstance().bRenderToMain) { diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 4dc8789796..46eac1927f 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -21,10 +21,6 @@ #include #include -#ifdef __APPLE__ -#include -#endif - #include "Common/CDUtils.h" #include "Common/CommonTypes.h" #include "Common/FileSearch.h" @@ -1014,10 +1010,7 @@ void CFrame::StartGame(const std::string& filename) } #if defined(__APPLE__) - NSView* view = (NSView*)m_RenderFrame->GetHandle(); - NSWindow* window = [view window]; - - [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; + m_RenderFrame->EnableFullScreenView(true); #endif wxBeginBusyCursor(); @@ -1233,10 +1226,7 @@ void CFrame::OnStopped() { #if defined(__APPLE__) // Disable the full screen button when not in a game. - NSView* view = (NSView*)m_RenderFrame->GetHandle(); - NSWindow* window = [view window]; - - [window setCollectionBehavior:NSWindowCollectionBehaviorDefault]; + m_RenderFrame->EnableFullScreenView(false); #endif // Make sure the window is not longer set to stay on top diff --git a/Source/Core/DolphinWX/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties.cpp index 74352fd5ca..709e66b4db 100644 --- a/Source/Core/DolphinWX/ISOProperties.cpp +++ b/Source/Core/DolphinWX/ISOProperties.cpp @@ -2,10 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#ifdef __APPLE__ -#import -#endif - #include #include #include @@ -1235,9 +1231,9 @@ bool CISOProperties::SaveGameConfig() void CISOProperties::LaunchExternalEditor(const std::string& filename, bool wait_until_closed) { #ifdef __APPLE__ - // wxTheMimeTypesManager is not yet implemented for wxCocoa - [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:filename.c_str()] - withApplication:@"TextEdit"]; + // GetOpenCommand does not work for wxCocoa + const char* OpenCommandConst[] = {"open", "-a", "TextEdit", filename.c_str(), NULL}; + char** OpenCommand = const_cast(OpenCommandConst); #else wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension("ini"); if (filetype == nullptr) // From extension failed, trying with MIME type now @@ -1256,6 +1252,7 @@ void CISOProperties::LaunchExternalEditor(const std::string& filename, bool wait WxUtils::ShowErrorDialog(_("Couldn't find open command for extension 'ini'!")); return; } +#endif long result; @@ -1269,7 +1266,6 @@ void CISOProperties::LaunchExternalEditor(const std::string& filename, bool wait WxUtils::ShowErrorDialog(_("wxExecute returned -1 on application run!")); return; } -#endif } void CISOProperties::GenerateLocalIniModified() diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 20460e258c..5a892b55f4 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -70,10 +70,6 @@ #endif -#ifdef __APPLE__ -#import -#endif - class wxFrame; // ------------ diff --git a/Source/Core/DolphinWX/WxUtils.cpp b/Source/Core/DolphinWX/WxUtils.cpp index fb33991d6b..c9449df3f8 100644 --- a/Source/Core/DolphinWX/WxUtils.cpp +++ b/Source/Core/DolphinWX/WxUtils.cpp @@ -17,10 +17,6 @@ #include "DolphinWX/WxUtils.h" -#ifdef __APPLE__ -#import -#endif - namespace WxUtils { // Launch a file according to its mime type