Fixed bug 3609 - Windows build fails due to conflicting types for 'XINPUT_GAMEPAD_EX'
authorSam Lantinga <slouken@libsdl.org>
Mon, 10 Jul 2017 18:31:28 -0700
changeset 11138c936a84f05ba
parent 11137 15f027d062f8
child 11139 4c165b1a0596
Fixed bug 3609 - Windows build fails due to conflicting types for 'XINPUT_GAMEPAD_EX'

Ozkan Sezer

(In reply to Ryan C. Gordon from comment #9)
> I've put this patch in as https://hg.libsdl.org/SDL/rev/117d4ce1390e ...can
> you verify this works on the latest MinGW?
>
> Thanks,
> --ryan.


This patch is wrong: the structure in question has nothing to do with any
gcc version in use. I suggest reverting this adding a conigury check for
it, instead. Something like the following should do it: (configure needs
regenerating.)
CMakeLists.txt
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/core/windows/SDL_windows.h
src/core/windows/SDL_xinput.h
     1.1 --- a/CMakeLists.txt	Mon Jul 10 17:16:12 2017 -0700
     1.2 +++ b/CMakeLists.txt	Mon Jul 10 18:31:28 2017 -0700
     1.3 @@ -1095,6 +1095,16 @@
     1.4          #include <windows.h>
     1.5          #include <xinput.h>
     1.6          int main(int argc, char **argv) { }" HAVE_XINPUT_H)
     1.7 +      check_c_source_compiles("
     1.8 +        #include <windows.h>
     1.9 +        #include <xinput.h>
    1.10 +        XINPUT_GAMEPAD_EX x1;
    1.11 +        int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
    1.12 +      check_c_source_compiles("
    1.13 +        #include <windows.h>
    1.14 +        #include <xinput.h>
    1.15 +        XINPUT_STATE_EX s1;
    1.16 +        int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
    1.17      else()
    1.18        check_include_file(xinput.h HAVE_XINPUT_H)
    1.19      endif()
     2.1 --- a/configure	Mon Jul 10 17:16:12 2017 -0700
     2.2 +++ b/configure	Mon Jul 10 18:31:28 2017 -0700
     2.3 @@ -22687,6 +22687,44 @@
     2.4  fi
     2.5  
     2.6  
     2.7 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
     2.8 +/* end confdefs.h.  */
     2.9 +
    2.10 +#include <windows.h>
    2.11 +#include <xinput.h>
    2.12 +XINPUT_GAMEPAD_EX x1;
    2.13 +
    2.14 +int
    2.15 +main ()
    2.16 +{
    2.17 +
    2.18 +  ;
    2.19 +  return 0;
    2.20 +}
    2.21 +_ACEOF
    2.22 +if ac_fn_c_try_compile "$LINENO"; then :
    2.23 +  have_xinput_gamepadex=yes
    2.24 +fi
    2.25 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    2.26 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    2.27 +/* end confdefs.h.  */
    2.28 +
    2.29 +#include <windows.h>
    2.30 +#include <xinput.h>
    2.31 +XINPUT_STATE_EX s1;
    2.32 +
    2.33 +int
    2.34 +main ()
    2.35 +{
    2.36 +
    2.37 +  ;
    2.38 +  return 0;
    2.39 +}
    2.40 +_ACEOF
    2.41 +if ac_fn_c_try_compile "$LINENO"; then :
    2.42 +  have_xinput_stateex=yes
    2.43 +fi
    2.44 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    2.45  
    2.46          if test x$have_ddraw = xyes; then
    2.47  
    2.48 @@ -22713,6 +22751,16 @@
    2.49  $as_echo "#define HAVE_XINPUT_H 1" >>confdefs.h
    2.50  
    2.51          fi
    2.52 +        if test x$have_xinput_gamepadex = xyes; then
    2.53 +
    2.54 +$as_echo "#define HAVE_XINPUT_GAMEPAD_EX 1" >>confdefs.h
    2.55 +
    2.56 +        fi
    2.57 +        if test x$have_xinput_stateex = xyes; then
    2.58 +
    2.59 +$as_echo "#define HAVE_XINPUT_STATE_EX 1" >>confdefs.h
    2.60 +
    2.61 +        fi
    2.62  
    2.63          SUMMARY_video="${SUMMARY_video} directx"
    2.64          SUMMARY_audio="${SUMMARY_audio} directx"
     3.1 --- a/configure.in	Mon Jul 10 17:16:12 2017 -0700
     3.2 +++ b/configure.in	Mon Jul 10 18:31:28 2017 -0700
     3.3 @@ -2801,6 +2801,16 @@
     3.4          AC_CHECK_HEADER(dxgi.h, have_dxgi=yes)
     3.5          AC_CHECK_HEADER(xaudio2.h, have_xaudio2=yes)
     3.6          AC_CHECK_HEADER(xinput.h, have_xinput=yes)
     3.7 +        AC_TRY_COMPILE([
     3.8 +#include <windows.h>
     3.9 +#include <xinput.h>
    3.10 +XINPUT_GAMEPAD_EX x1;
    3.11 +        ],[],[have_xinput_gamepadex=yes])
    3.12 +        AC_TRY_COMPILE([
    3.13 +#include <windows.h>
    3.14 +#include <xinput.h>
    3.15 +XINPUT_STATE_EX s1;
    3.16 +        ],[],[have_xinput_stateex=yes])
    3.17  
    3.18          if test x$have_ddraw = xyes; then
    3.19              AC_DEFINE(HAVE_DDRAW_H, 1, [ ])
    3.20 @@ -2817,6 +2827,12 @@
    3.21          if test x$have_xinput = xyes; then
    3.22              AC_DEFINE(HAVE_XINPUT_H, 1, [ ])
    3.23          fi
    3.24 +        if test x$have_xinput_gamepadex = xyes; then
    3.25 +            AC_DEFINE(HAVE_XINPUT_GAMEPAD_EX, 1, [ ])
    3.26 +        fi
    3.27 +        if test x$have_xinput_stateex = xyes; then
    3.28 +            AC_DEFINE(HAVE_XINPUT_STATE_EX, 1, [ ])
    3.29 +        fi
    3.30  
    3.31          SUMMARY_video="${SUMMARY_video} directx"
    3.32          SUMMARY_audio="${SUMMARY_audio} directx"
     4.1 --- a/include/SDL_config.h.cmake	Mon Jul 10 17:16:12 2017 -0700
     4.2 +++ b/include/SDL_config.h.cmake	Mon Jul 10 18:31:28 2017 -0700
     4.3 @@ -55,6 +55,8 @@
     4.4  #cmakedefine HAVE_XAUDIO2_H @HAVE_XAUDIO2_H@
     4.5  #cmakedefine HAVE_XINPUT_H @HAVE_XINPUT_H@
     4.6  #cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@
     4.7 +#cmakedefine HAVE_XINPUT_GAMEPAD_EX @HAVE_XINPUT_GAMEPAD_EX@
     4.8 +#cmakedefine HAVE_XINPUT_STATE_EX @HAVE_XINPUT_STATE_EX@
     4.9  
    4.10  /* Comment this if you want to build without any C library requirements */
    4.11  #cmakedefine HAVE_LIBC 1
     5.1 --- a/include/SDL_config.h.in	Mon Jul 10 17:16:12 2017 -0700
     5.2 +++ b/include/SDL_config.h.in	Mon Jul 10 18:31:28 2017 -0700
     5.3 @@ -55,6 +55,8 @@
     5.4  #undef HAVE_DSOUND_H
     5.5  #undef HAVE_DXGI_H
     5.6  #undef HAVE_XINPUT_H
     5.7 +#undef HAVE_XINPUT_GAMEPAD_EX
     5.8 +#undef HAVE_XINPUT_STATE_EX
     5.9  
    5.10  /* Comment this if you want to build without any C library requirements */
    5.11  #undef HAVE_LIBC
     6.1 --- a/src/core/windows/SDL_windows.h	Mon Jul 10 17:16:12 2017 -0700
     6.2 +++ b/src/core/windows/SDL_windows.h	Mon Jul 10 18:31:28 2017 -0700
     6.3 @@ -35,6 +35,7 @@
     6.4  #endif
     6.5  
     6.6  #include <windows.h>
     6.7 +#include <basetyps.h>   /* for REFIID with broken mingw.org headers */
     6.8  
     6.9  /* Routines to convert from UTF8 to native Windows text */
    6.10  #if UNICODE
     7.1 --- a/src/core/windows/SDL_xinput.h	Mon Jul 10 17:16:12 2017 -0700
     7.2 +++ b/src/core/windows/SDL_xinput.h	Mon Jul 10 18:31:28 2017 -0700
     7.3 @@ -101,13 +101,7 @@
     7.4  
     7.5  /* typedef's for XInput structs we use */
     7.6  
     7.7 -/* Don't redeclare these on MinGW with gcc >= 5.0.2 */
     7.8 -#if defined(__MINGW32__) && (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= 50002)
     7.9 -#define HAS_XINPUT_GAMEPAD_EX
    7.10 -#define HAS_XINPUT_STATE_EX
    7.11 -#endif
    7.12 -
    7.13 -#ifndef HAS_XINPUT_GAMEPAD_EX
    7.14 +#ifndef HAVE_XINPUT_GAMEPAD_EX
    7.15  typedef struct
    7.16  {
    7.17      WORD wButtons;
    7.18 @@ -121,7 +115,7 @@
    7.19  } XINPUT_GAMEPAD_EX;
    7.20  #endif
    7.21  
    7.22 -#ifndef HAS_XINPUT_STATE_EX
    7.23 +#ifndef HAVE_XINPUT_STATE_EX
    7.24  typedef struct
    7.25  {
    7.26      DWORD dwPacketNumber;