Fix build on Windows targets without dxgi.h, like MingW32.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 06 May 2014 00:13:07 -0400
changeset 8751 e8c61640668d
parent 8750 5064096ddaf7
child 8752 44d31ae3d104
Fix build on Windows targets without dxgi.h, like MingW32.
CMakeLists.txt
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_config_windows.h
include/SDL_config_winrt.h
src/video/windows/SDL_windowsvideo.c
--- a/CMakeLists.txt	Fri May 02 12:39:26 2014 -0700
+++ b/CMakeLists.txt	Tue May 06 00:13:07 2014 -0400
@@ -804,6 +804,7 @@
     check_include_file(dsound.h HAVE_DSOUND_H)
     check_include_file(dinput.h HAVE_DINPUT_H)
     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
+    check_include_file(dxgi.h HAVE_DXGI_H)
     if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
       set(HAVE_DIRECTX TRUE)
       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
--- a/configure.in	Fri May 02 12:39:26 2014 -0700
+++ b/configure.in	Tue May 06 00:13:07 2014 -0400
@@ -2404,6 +2404,7 @@
         AC_CHECK_HEADER(dsound.h, have_dsound=yes)
         AC_CHECK_HEADER(dinput.h, have_dinput=yes)
         AC_CHECK_HEADER(xaudio2.h, have_xaudio2=yes)
+        AC_CHECK_HEADER(dxgi.h, have_dxgi=yes)
 
         SUMMARY_video="${SUMMARY_video} directx"
         SUMMARY_audio="${SUMMARY_audio} directx"
@@ -2830,6 +2831,9 @@
                 AC_DEFINE(SDL_VIDEO_RENDER_D3D11, 1, [ ])
             fi
         fi
+        if test x$have_dxgi = xyes; then
+            AC_DEFINE(HAVE_DXGI_H, 1, [ ])
+        fi
         # Set up files for the audio library
         if test x$enable_audio = xyes; then
             AC_DEFINE(SDL_AUDIO_DRIVER_WINMM, 1, [ ])
--- a/include/SDL_config.h.cmake	Fri May 02 12:39:26 2014 -0700
+++ b/include/SDL_config.h.cmake	Tue May 06 00:13:07 2014 -0400
@@ -48,6 +48,8 @@
 #cmakedefine HAVE_GCC_SYNC_LOCK_TEST_AND_SET @HAVE_GCC_SYNC_LOCK_TEST_AND_SET@
 #cmakedefine HAVE_PTHREAD_SPINLOCK @HAVE_PTHREAD_SPINLOCK@
 
+#cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@
+
 /* Comment this if you want to build without any C library requirements */
 #cmakedefine HAVE_LIBC 1
 #if HAVE_LIBC
--- a/include/SDL_config.h.in	Fri May 02 12:39:26 2014 -0700
+++ b/include/SDL_config.h.in	Tue May 06 00:13:07 2014 -0400
@@ -51,6 +51,8 @@
 #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
 #undef HAVE_PTHREAD_SPINLOCK
 
+#undef HAVE_DXGI_H
+
 /* Comment this if you want to build without any C library requirements */
 #undef HAVE_LIBC
 #if HAVE_LIBC
--- a/include/SDL_config_windows.h	Fri May 02 12:39:26 2014 -0700
+++ b/include/SDL_config_windows.h	Tue May 06 00:13:07 2014 -0400
@@ -76,6 +76,8 @@
 # define SIZEOF_VOIDP 4
 #endif
 
+#define HAVE_DXGI_H 1
+
 /* This is disabled by default to avoid C runtime dependencies and manifest requirements */
 #ifdef HAVE_LIBC
 /* Useful headers */
--- a/include/SDL_config_winrt.h	Fri May 02 12:39:26 2014 -0700
+++ b/include/SDL_config_winrt.h	Tue May 06 00:13:07 2014 -0400
@@ -77,6 +77,7 @@
 #endif
 
 /* Useful headers */
+#define HAVE_DXGI_H 1
 #define HAVE_LIBC 1
 #define HAVE_STDIO_H 1
 #define STDC_HEADERS 1
--- a/src/video/windows/SDL_windowsvideo.c	Fri May 02 12:39:26 2014 -0700
+++ b/src/video/windows/SDL_windowsvideo.c	Tue May 06 00:13:07 2014 -0400
@@ -245,11 +245,12 @@
     }
 }
 
+#if HAVE_DXGI_H
 #define CINTERFACE
 #define COBJMACROS
 #include <dxgi.h>
 
-SDL_bool 
+static SDL_bool
 DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
 {
     *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
@@ -277,18 +278,25 @@
         return SDL_FALSE;
     }
 }
+#endif
 
 
 SDL_bool
 SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
 {
+#if !HAVE_DXGI_H
+    if (adapterIndex) *adapterIndex = -1;
+    if (outputIndex) *outputIndex = -1;
+    SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header");
+    return SDL_FALSE;
+#else
     SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
     void *pDXGIDLL;
+    char *displayName;
+    int nAdapter, nOutput;
     IDXGIFactory *pDXGIFactory;
     IDXGIAdapter *pDXGIAdapter;
     IDXGIOutput* pDXGIOutput;
-    char *displayName;
-    int nAdapter, nOutput;
 
     if (!adapterIndex) {
         SDL_InvalidParamError("adapterIndex");
@@ -344,6 +352,7 @@
     } else {
         return SDL_TRUE;
     }
+#endif
 }
 
 #endif /* SDL_VIDEO_DRIVER_WINDOWS */