From 70e44b846ceaf9eebc336b12a07406c3a418a5c3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 20 Jun 2014 04:57:46 +0200 Subject: Enable compatibility w/ gcc/mingw64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These changes enable gcc/mingw64 compatibility. Besides adding fixes of my own, the following changes were considered: https://github.com/parasti/OculusSDK-MinGW/commit/8fa94f4cc1d7e9d34a1908a4d69df52e5d998a20 https://github.com/parasti/OculusSDK-MinGW/commit/b4681523477b15bea94379eb11b17be9daa7ac17 https://github.com/larspensjo/OculusSDK-MinGW/commit/213118fdc1798a54b4efb930c3427b694abd8b31 Big KUDOS to - Jānis Rūcis aka 'parasti' - Lars Pensjö aka 'larspensjo' --- LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp | 7 ++++--- LibOVR/Src/OVR_CAPI.cpp | 6 +++++- LibOVR/Src/OVR_Profile.cpp | 2 +- LibOVR/Src/OVR_SensorImpl.cpp | 4 ++-- LibOVR/Src/OVR_Win32_DeviceStatus.cpp | 5 +++++ LibOVR/Src/OVR_Win32_HIDDevice.cpp | 2 +- LibOVR/Src/OVR_Win32_HIDDevice.h | 1 + LibOVR/Src/OVR_Win32_HMDDevice.cpp | 2 +- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp b/LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp index 91a5e31..1779fb0 100644 --- a/LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp +++ b/LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp @@ -821,7 +821,7 @@ unsigned WINAPI Thread_Win32StartFn(void * phandle) // Ensure that ThreadId is assigned once thread is running, in case // beginthread hasn't filled it in yet. - pthread->IdValue = (ThreadId)::GetCurrentThreadId(); + pthread->IdValue = (ThreadId)(intptr_t)::GetCurrentThreadId(); // should be: typedef intptr_t ThreadId; DWORD result = pthread->PRun(); // Signal the thread as done and release it atomically. @@ -953,7 +953,8 @@ bool Thread::MSleep(unsigned msecs) void Thread::SetThreadName( const char* name ) { -#if !defined(OVR_BUILD_SHIPPING) || defined(OVR_BUILD_PROFILING) + // MinGW does not support SEH exceptions, hence CPP: && defined(OVR_CC_MSVC) +#if ( !defined(OVR_BUILD_SHIPPING) || defined(OVR_BUILD_PROFILING) ) && defined(OVR_CC_MSVC) // Looks ugly, but it is the recommended way to name a thread. typedef struct tagTHREADNAME_INFO { DWORD dwType; // Must be 0x1000 @@ -995,7 +996,7 @@ int Thread::GetCPUCount() // comparison purposes. ThreadId GetCurrentThreadId() { - return (ThreadId)::GetCurrentThreadId(); + return (ThreadId)(intptr_t)::GetCurrentThreadId(); // should be: typedef intptr_t ThreadId; } } // OVR diff --git a/LibOVR/Src/OVR_CAPI.cpp b/LibOVR/Src/OVR_CAPI.cpp index a7f921f..497d1a2 100644 --- a/LibOVR/Src/OVR_CAPI.cpp +++ b/LibOVR/Src/OVR_CAPI.cpp @@ -670,7 +670,11 @@ OVR_EXPORT ovrEyeRenderDesc ovrHmd_GetRenderDesc(ovrHmd hmd, -#define OVR_OFFSET_OF(s, field) ((size_t)&((s*)0)->field) +#if defined(OVR_CC_MSVC) + #define OVR_OFFSET_OF(s, field) ((size_t)&((s*)0)->field) +#else + #define OVR_OFFSET_OF(s, field) (1) +#endif diff --git a/LibOVR/Src/OVR_Profile.cpp b/LibOVR/Src/OVR_Profile.cpp index 4844c29..12f4a46 100644 --- a/LibOVR/Src/OVR_Profile.cpp +++ b/LibOVR/Src/OVR_Profile.cpp @@ -40,7 +40,7 @@ limitations under the License. #include "Kernel/OVR_Array.h" #ifdef OVR_OS_WIN32 -#include +#include #else #include #include diff --git a/LibOVR/Src/OVR_SensorImpl.cpp b/LibOVR/Src/OVR_SensorImpl.cpp index 91ae7e0..c7d3acd 100644 --- a/LibOVR/Src/OVR_SensorImpl.cpp +++ b/LibOVR/Src/OVR_SensorImpl.cpp @@ -870,7 +870,7 @@ bool SensorDeviceImpl::SetMagCalibrationReport(const MagCalibrationReport &data) // time stamp the calibration char time_str[64]; -#ifdef OVR_OS_WIN32 +#if defined(OVR_OS_WIN32) && defined(OVR_CC_MSVC) struct tm caltime; time_t now = time(0); localtime_s(&caltime, &now); @@ -1074,7 +1074,7 @@ bool SensorDeviceImpl::GetMagCalibrationReport(MagCalibrationReport* data) tm ct; memset(&ct, 0, sizeof(tm)); -#ifdef OVR_OS_WIN32 +#if defined(OVR_OS_WIN32) && defined(OVR_CC_MSVC) struct tm nowtime; localtime_s(&nowtime, &now); ct.tm_isdst = nowtime.tm_isdst; diff --git a/LibOVR/Src/OVR_Win32_DeviceStatus.cpp b/LibOVR/Src/OVR_Win32_DeviceStatus.cpp index 1dfcd6a..6eee1c0 100644 --- a/LibOVR/Src/OVR_Win32_DeviceStatus.cpp +++ b/LibOVR/Src/OVR_Win32_DeviceStatus.cpp @@ -32,6 +32,11 @@ limitations under the License. #include +#ifndef DEVICE_NOTIFY_ALL_INTERFACE_CLASSES +// Normally defined in winuser.h +#define DEVICE_NOTIFY_ALL_INTERFACE_CLASSES 0x00000004 +#endif + namespace OVR { namespace Win32 { static TCHAR windowClassName[] = TEXT("LibOVR_DeviceStatus_WindowClass"); diff --git a/LibOVR/Src/OVR_Win32_HIDDevice.cpp b/LibOVR/Src/OVR_Win32_HIDDevice.cpp index 75d71f4..67d9204 100644 --- a/LibOVR/Src/OVR_Win32_HIDDevice.cpp +++ b/LibOVR/Src/OVR_Win32_HIDDevice.cpp @@ -289,7 +289,7 @@ bool HIDDevice::HIDInitialize(const String& path) if (!openDevice()) { - LogText("OVR::Win32::HIDDevice - Failed to open HIDDevice: ", path); + LogText("OVR::Win32::HIDDevice - Failed to open HIDDevice: ", path.ToCStr()); return false; } diff --git a/LibOVR/Src/OVR_Win32_HIDDevice.h b/LibOVR/Src/OVR_Win32_HIDDevice.h index 4e75914..c186ccd 100644 --- a/LibOVR/Src/OVR_Win32_HIDDevice.h +++ b/LibOVR/Src/OVR_Win32_HIDDevice.h @@ -31,6 +31,7 @@ limitations under the License. #include "OVR_Win32_DeviceManager.h" #include +#include // Needed for declaration of NTSTATUS #include //------------------------------------------------------------------------------------- diff --git a/LibOVR/Src/OVR_Win32_HMDDevice.cpp b/LibOVR/Src/OVR_Win32_HMDDevice.cpp index e16a060..c0fc5ae 100644 --- a/LibOVR/Src/OVR_Win32_HMDDevice.cpp +++ b/LibOVR/Src/OVR_Win32_HMDDevice.cpp @@ -297,7 +297,7 @@ void HMDDeviceFactory::EnumerateDevices(EnumerateVisitor& visitor) { info.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(monitors.Monitors[m], &info); - if (_tcsstr(ddm.DeviceName, info.szDevice) == ddm.DeviceName) + if (wcsstr(ddm.DeviceName, info.szDevice) == ddm.DeviceName) { // If the device name starts with the monitor name // then we found the matching DISPLAY_DEVICE and MONITORINFO // so we can gather the monitor coordinates -- cgit v1.2.3