Fix builds with MingW.

This commit is contained in:
Rokas Kupstys 2019-01-19 13:03:30 +02:00
parent 32f0a27d3b
commit 8157e3a0b3
11 changed files with 69 additions and 45 deletions

View File

@ -22,7 +22,7 @@
namespace tracy
{
#ifdef _MSC_VER
#ifdef _WIN32
# define DLL_IMPORT __declspec(dllimport)
#else
# define DLL_IMPORT

View File

@ -1,6 +1,6 @@
#ifdef TRACY_ENABLE
#ifdef _MSC_VER
#ifdef _WIN32
# ifndef NOMINMAX
# define NOMINMAX
# endif
@ -57,7 +57,7 @@
# include <setjmp.h>
#endif
#if defined _MSC_VER || defined __CYGWIN__
#if defined _WIN32 || defined __CYGWIN__
# include <lmcons.h>
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
@ -193,7 +193,7 @@ static int64_t SetupHwTimer()
static const char* GetProcessName()
{
const char* processName = "unknown";
#if defined _MSC_VER
#ifdef _WIN32
static char buf[_MAX_PATH];
GetModuleFileNameA( nullptr, buf, _MAX_PATH );
const char* ptr = buf;
@ -216,7 +216,7 @@ static const char* GetHostInfo()
{
static char buf[1024];
auto ptr = buf;
#if defined _MSC_VER || defined __CYGWIN__
#if defined _WIN32 || defined __CYGWIN__
# ifdef UNICODE
t_RtlGetVersion RtlGetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandle( L"ntdll.dll" ), "RtlGetVersion" );
# else
@ -225,10 +225,12 @@ static const char* GetHostInfo()
if( !RtlGetVersion )
{
# ifndef __CYGWIN__
ptr += sprintf( ptr, "OS: Windows\n" );
# else
# ifdef __CYGWIN__
ptr += sprintf( ptr, "OS: Windows (Cygwin)\n" );
# elif defined __MINGW32__
ptr += sprintf( ptr, "OS: Windows (MingW)\n" );
# else
ptr += sprintf( ptr, "OS: Windows\n" );
# endif
}
else
@ -236,10 +238,12 @@ static const char* GetHostInfo()
RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) };
RtlGetVersion( &ver );
# ifndef __CYGWIN__
ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
# else
# ifdef __CYGWIN__
ptr += sprintf( ptr, "OS: Windows %i.%i.%i (Cygwin)\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
# elif defined __MINGW32__
ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber );
# else
ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
# endif
}
#elif defined __linux__
@ -280,7 +284,7 @@ static const char* GetHostInfo()
ptr += sprintf( ptr, "Compiler: unknown\n" );
#endif
#if defined _MSC_VER || defined __CYGWIN__
#ifdef _WIN32
# ifndef __CYGWIN__
InitWinSock();
# endif
@ -332,7 +336,7 @@ static const char* GetHostInfo()
auto modelPtr = cpuModel;
for( uint32_t i=0x80000002; i<0x80000005; ++i )
{
# if defined _MSC_VER || defined __CYGWIN__
# if defined _WIN32 || defined __CYGWIN__
__cpuidex( (int*)regs, i, 0 );
# else
int zero = 0;
@ -346,7 +350,7 @@ static const char* GetHostInfo()
ptr += sprintf( ptr, "CPU: unknown\n" );
#endif
#if defined _MSC_VER || defined __CYGWIN__
#if defined _WIN32 || defined __CYGWIN__
MEMORYSTATUSEX statex;
statex.dwLength = sizeof( statex );
GlobalMemoryStatusEx( &statex );
@ -366,13 +370,13 @@ static const char* GetHostInfo()
return buf;
}
#ifdef _MSC_VER
#ifdef _WIN32
static DWORD s_profilerThreadId = 0;
static char s_crashText[1024];
LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
{
const auto ec = pExp->ExceptionRecord->ExceptionCode;
const unsigned ec = pExp->ExceptionRecord->ExceptionCode;
auto msgPtr = s_crashText;
switch( ec )
{
@ -381,13 +385,13 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
switch( pExp->ExceptionRecord->ExceptionInformation[0] )
{
case 0:
msgPtr += sprintf( msgPtr, "Read violation at address 0x%Iu.", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "Read violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
case 1:
msgPtr += sprintf( msgPtr, "Write violation at address 0x%Iu.", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "Write violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
case 8:
msgPtr += sprintf( msgPtr, "DEP violation at address 0x%Iu.", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "DEP violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
default:
break;
@ -752,7 +756,7 @@ thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false };
static Profiler init_order(105) s_profilerInstance;
Profiler& s_profiler = s_profilerInstance;
#ifdef _MSC_VER
#ifdef _WIN32
# define DLL_EXPORT __declspec(dllexport)
#else
# define DLL_EXPORT __attribute__((visibility("default")))
@ -850,8 +854,14 @@ Profiler::Profiler()
new(s_thread) Thread( LaunchWorker, this );
SetThreadName( s_thread->Handle(), "Tracy Profiler" );
#ifdef _MSC_VER
#if defined PTW32_VERSION
s_profilerThreadId = pthread_getw32threadid_np( s_thread->Handle() );
#elif defined __WINPTHREADS_VERSION
s_profilerThreadId = GetThreadId( (HANDLE)pthread_gethandle( s_thread->Handle() ) );
#elif defined _MSC_VER
s_profilerThreadId = GetThreadId( s_thread->Handle() );
#endif
#if defined _WIN32
AddVectoredExceptionHandler( 1, CrashFilter );
#endif

View File

@ -17,13 +17,13 @@
#include "../common/TracyMutex.hpp"
#include "../common/TracySystem.hpp"
#if defined _MSC_VER || defined __CYGWIN__
#if defined _WIN32 || defined __CYGWIN__
# include <intrin.h>
#endif
#if defined _MSC_VER || defined __CYGWIN__ || ( ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) && !defined __ANDROID__ ) || __ARM_ARCH >= 6
#if defined _WIN32 || defined __CYGWIN__ || ( ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) && !defined __ANDROID__ ) || __ARM_ARCH >= 6
# define TRACY_HW_TIMER
# if defined _MSC_VER || defined __CYGWIN__
# if defined _WIN32 || defined __CYGWIN__
// Enable optimization for MSVC __rdtscp() intrin, saving one LHS of a cpu value on the stack.
// This comes at the cost of an unaligned memory write.
# define TRACY_RDTSCP_OPT
@ -93,7 +93,7 @@ public:
# if __ARM_ARCH >= 6
cpu = 0xFFFFFFFF;
return GetTimeImpl();
# elif defined _MSC_VER || defined __CYGWIN__
# elif defined _WIN32 || defined __CYGWIN__
const auto t = int64_t( __rdtscp( &cpu ) );
return t;
# elif defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64
@ -112,7 +112,7 @@ public:
#ifdef TRACY_HW_TIMER
# if __ARM_ARCH >= 6
return GetTimeImpl();
# elif defined _MSC_VER || defined __CYGWIN__
# elif defined _WIN32 || defined __CYGWIN__
unsigned int dontcare;
const auto t = int64_t( __rdtscp( &dontcare ) );
return t;

View File

@ -9,11 +9,13 @@
#include "TracyAlloc.hpp"
#include "TracySocket.hpp"
#ifdef _MSC_VER
#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
# pragma warning(disable:4244)
# pragma warning(disable:4267)
# ifdef _MSC_VER
# pragma warning(disable:4244)
# pragma warning(disable:4267)
# endif
#else
# include <sys/socket.h>
# include <netdb.h>
@ -27,13 +29,13 @@
namespace tracy
{
#ifdef _MSC_VER
#ifdef _WIN32
typedef SOCKET socket_t;
#else
typedef int socket_t;
#endif
#ifdef _MSC_VER
#ifdef _WIN32
struct __wsinit
{
__wsinit()
@ -59,7 +61,7 @@ Socket::Socket()
, m_bufPtr( nullptr )
, m_bufLeft( 0 )
{
#ifdef _MSC_VER
#ifdef _WIN32
InitWinSock();
#endif
}
@ -103,7 +105,7 @@ bool Socket::Connect( const char* addr, const char* port )
#endif
if( connect( sock, ptr->ai_addr, ptr->ai_addrlen ) == -1 )
{
#ifdef _MSC_VER
#ifdef _WIN32
closesocket( sock );
#else
close( sock );
@ -122,7 +124,7 @@ bool Socket::Connect( const char* addr, const char* port )
void Socket::Close()
{
assert( m_sock != -1 );
#ifdef _MSC_VER
#ifdef _WIN32
closesocket( m_sock );
#else
close( m_sock );
@ -183,7 +185,7 @@ int Socket::Recv( void* _buf, int len, const timeval* tv )
FD_ZERO( &fds );
FD_SET( static_cast<socket_t>(m_sock), &fds );
#ifndef _WIN32
#if !defined _WIN32 || defined __MINGW32__
timeval _tv = *tv;
select( m_sock+1, &fds, nullptr, nullptr, &_tv );
#else
@ -260,7 +262,7 @@ bool Socket::HasData()
ListenSocket::ListenSocket()
: m_sock( -1 )
{
#ifdef _MSC_VER
#ifdef _WIN32
InitWinSock();
#endif
}
@ -284,7 +286,7 @@ bool ListenSocket::Listen( const char* port, int backlog )
if( getaddrinfo( nullptr, port, &hints, &res ) != 0 ) return false;
m_sock = socket( res->ai_family, res->ai_socktype, res->ai_protocol );
#if defined _MSC_VER || defined __CYGWIN__
#if defined _WIN32 || defined __CYGWIN__
unsigned long val = 0;
setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) );
#else
@ -337,7 +339,7 @@ Socket* ListenSocket::Accept()
void ListenSocket::Close()
{
assert( m_sock != -1 );
#ifdef _MSC_VER
#ifdef _WIN32
closesocket( m_sock );
#else
close( m_sock );

View File

@ -8,7 +8,7 @@ struct timeval;
namespace tracy
{
#ifdef _MSC_VER
#ifdef _WIN32
void InitWinSock();
#endif

View File

@ -21,6 +21,9 @@
# include <fcntl.h>
#endif
#ifdef __MINGW32__
# define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include <stdio.h>
@ -51,7 +54,7 @@ void SetThreadName( std::thread& thread, const char* name )
void SetThreadName( std::thread::native_handle_type handle, const char* name )
{
#ifdef _WIN32
#if defined _WIN32 && !defined PTW32_VERSION && !defined __WINPTHREADS_VERSION
# if defined NTDDI_WIN10_RS2 && NTDDI_VERSION >= NTDDI_WIN10_RS2
wchar_t buf[256];
mbstowcs( buf, name, 256 );
@ -108,7 +111,13 @@ void SetThreadName( std::thread::native_handle_type handle, const char* name )
buf[sz+1] = '\0';
auto data = (ThreadNameData*)tracy_malloc( sizeof( ThreadNameData ) );
# ifdef _WIN32
# if defined PTW32_VERSION
data->id = pthread_getw32threadid_np( static_cast<pthread_t>( handle ) );
# elif defined __WINPTHREADS_VERSION
data->id = GetThreadId( pthread_gethandle( static_cast<pthread_t>( handle ) ) );
# else
data->id = GetThreadId( static_cast<HANDLE>( handle ) );
# endif
# elif defined __APPLE__
pthread_threadid_np( handle, &data->id );
# else

View File

@ -2,7 +2,7 @@
#define __TRACYSYSTEM_HPP__
#ifdef TRACY_ENABLE
# if defined __ANDROID__ || defined __CYGWIN__ || defined __APPLE__ || defined _GNU_SOURCE || ( defined _WIN32 && ( !defined NTDDI_WIN10_RS2 || NTDDI_VERSION < NTDDI_WIN10_RS2 ) )
# if defined __ANDROID__ || defined __CYGWIN__ || defined __MINGW32__ || defined __APPLE__ || defined _GNU_SOURCE || ( defined _WIN32 && ( !defined NTDDI_WIN10_RS2 || NTDDI_VERSION < NTDDI_WIN10_RS2 ) )
# define TRACY_COLLECT_THREAD_NAMES
# endif
#endif

View File

@ -1,7 +1,7 @@
#ifndef __TRACYPOPCNT_HPP__
#define __TRACYPOPCNT_HPP__
#ifdef _MSC_VER
#ifdef _WIN32
# include <intrin.h>
# define TracyCountBits __popcnt64
#else

View File

@ -8,10 +8,10 @@
#else
# include <dirent.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# include <errno.h>
#endif
#include <sys/stat.h>
#include "TracyStorage.hpp"

View File

@ -1,3 +1,6 @@
#ifdef __MINGW32__
# define __STDC_FORMAT_MACROS
#endif
#include <algorithm>
#include <assert.h>
#include <chrono>

View File

@ -1,10 +1,10 @@
#ifdef _MSC_VER
#ifdef _WIN32
# include <winsock2.h>
#else
# include <sys/time.h>
#endif
#if defined _MSC_VER || defined __MINGW32__
#ifdef _WIN32
# include <malloc.h>
#else
# include <alloca.h>