Skip to content

Commit 6e1b0b4

Browse files
committed
Fix more build errors in mingw
Based on #77
1 parent c514691 commit 6e1b0b4

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/D3D12MemAlloc.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@
3333
#include <shared_mutex>
3434
#endif
3535

36-
// Includes needed for MinGW - see #71.
37-
#ifndef _MSC_VER
38-
#include <guiddef.h>
39-
// guiddef.h must be included first.
40-
#include <dxguids.h>
36+
// On older mingw versions, using the Agility SDK will cause linker errors unless dxguids.h is included.
37+
// But on newer mingw versions, the includes aren't necessary thus no need to grab DirectX-Headers.
38+
// Release cycles are slow for LTS distros on Linux, so this codeblock will need to stay for a few years.
39+
#if defined(__MINGW64_VERSION_MAJOR) && defined(__MINGW64_VERSION_MINOR) && \
40+
defined(__MINGW64_VERSION_BUGFIX) && defined(__ID3D12Device8_INTERFACE_DEFINED__)
41+
#define D3D12MA_MAKE_MINGW_VERSION(x, y, z) ((x << 20u) | (y << 10u) | (z))
42+
#if D3D12MA_MAKE_MINGW_VERSION(__MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR, \
43+
__MINGW64_VERSION_BUGFIX) <= D3D12MA_MAKE_MINGW_VERSION(11, 0, 1)
44+
#if defined(__has_include)
45+
#if !__has_include(<dxguids.h>)
46+
#error "mingw or gcc detected. dxguids.h is needed. You can grab it from https://github.com/microsoft/DirectX-Headers or if you're on Ubuntu just run sudo apt install directx-headers-dev"
47+
#endif
48+
#endif
49+
#include <guiddef.h>
50+
// // guiddef.h must be included first.
51+
#include <dxguids.h>
52+
#endif
53+
#undef D3D12MA_MAKE_MINGW_VERSION
4154
#endif
4255

4356
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)