Commit f3835702d33dfdb65a835b98fe24aa1586a1bb72

Ozkan Sezer 2021-01-17T05:00:50

fix build with --disable-directx

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f749f6f..662658b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1421,26 +1421,6 @@ elseif(WINDOWS)
       set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
     endif()
 
-    if(HAVE_WIN32_CC)
-      # xinput.h may need windows.h, but doesn't include it itself.
-      check_c_source_compiles("
-        #include <windows.h>
-        #include <xinput.h>
-        int main(int argc, char **argv) { }" HAVE_XINPUT_H)
-      check_c_source_compiles("
-        #include <windows.h>
-        #include <xinput.h>
-        XINPUT_GAMEPAD_EX x1;
-        int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
-      check_c_source_compiles("
-        #include <windows.h>
-        #include <xinput.h>
-        XINPUT_STATE_EX s1;
-        int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
-    else()
-      check_include_file(xinput.h HAVE_XINPUT_H)
-    endif()
-
     check_include_file(d3d9.h HAVE_D3D_H)
     check_include_file(d3d11_1.h HAVE_D3D11_H)
     check_include_file(ddraw.h HAVE_DDRAW_H)
@@ -1461,6 +1441,26 @@ elseif(WINDOWS)
     set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   endif()
 
+  if(HAVE_WIN32_CC)
+    # xinput.h may need windows.h, but does not include it itself.
+    check_c_source_compiles("
+      #include <windows.h>
+      #include <xinput.h>
+      int main(int argc, char **argv) { }" HAVE_XINPUT_H)
+    check_c_source_compiles("
+      #include <windows.h>
+      #include <xinput.h>
+      XINPUT_GAMEPAD_EX x1;
+      int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
+    check_c_source_compiles("
+      #include <windows.h>
+      #include <xinput.h>
+      XINPUT_STATE_EX s1;
+      int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
+  else()
+    check_include_file(xinput.h HAVE_XINPUT_H)
+  endif()
+
   # headers needed elsewhere
   check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
   check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
diff --git a/configure b/configure
index 39aaee0..49fb94d 100755
--- a/configure
+++ b/configure
@@ -23865,13 +23865,44 @@ if test "x$ac_cv_header_dxgi_h" = xyes; then :
 fi
 
 
+
+        if test x$have_ddraw = xyes; then
+
+$as_echo "#define HAVE_DDRAW_H 1" >>confdefs.h
+
+        fi
+        if test x$have_dinput = xyes; then
+
+$as_echo "#define HAVE_DINPUT_H 1" >>confdefs.h
+
+        fi
+        if test x$have_dsound = xyes; then
+
+$as_echo "#define HAVE_DSOUND_H 1" >>confdefs.h
+
+        fi
+        if test x$have_dxgi = xyes; then
+
+$as_echo "#define HAVE_DXGI_H 1" >>confdefs.h
+
+        fi
+
+        # FIXME: latest Cygwin finds dinput headers, but we die on other win32 headers.
+        # FIXME:  ...so force it off for now.
+        case "$host" in
+            *-*-cygwin*)
+            have_dinput=false
+            ;;
+        esac
+    fi
+
         ac_fn_c_check_header_mongrel "$LINENO" "xinput.h" "ac_cv_header_xinput_h" "$ac_includes_default"
 if test "x$ac_cv_header_xinput_h" = xyes; then :
   have_xinput=yes
 fi
 
 
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 #include <windows.h>
@@ -23890,7 +23921,7 @@ if ac_fn_c_try_compile "$LINENO"; then :
   have_xinput_gamepadex=yes
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 #include <windows.h>
@@ -23910,49 +23941,20 @@ if ac_fn_c_try_compile "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-        if test x$have_ddraw = xyes; then
-
-$as_echo "#define HAVE_DDRAW_H 1" >>confdefs.h
-
-        fi
-        if test x$have_dinput = xyes; then
-
-$as_echo "#define HAVE_DINPUT_H 1" >>confdefs.h
-
-        fi
-        if test x$have_dsound = xyes; then
-
-$as_echo "#define HAVE_DSOUND_H 1" >>confdefs.h
-
-        fi
-        if test x$have_dxgi = xyes; then
-
-$as_echo "#define HAVE_DXGI_H 1" >>confdefs.h
-
-        fi
-        if test x$have_xinput = xyes; then
+    if test x$have_xinput = xyes; then
 
 $as_echo "#define HAVE_XINPUT_H 1" >>confdefs.h
 
-        fi
-        if test x$have_xinput_gamepadex = xyes; then
+    fi
+    if test x$have_xinput_gamepadex = xyes; then
 
 $as_echo "#define HAVE_XINPUT_GAMEPAD_EX 1" >>confdefs.h
 
-        fi
-        if test x$have_xinput_stateex = xyes; then
+    fi
+    if test x$have_xinput_stateex = xyes; then
 
 $as_echo "#define HAVE_XINPUT_STATE_EX 1" >>confdefs.h
 
-        fi
-
-        # FIXME: latest Cygwin finds dinput headers, but we die on other win32 headers.
-        # FIXME:  ...so force it off for now.
-        case "$host" in
-            *-*-cygwin*)
-            have_dinput=false
-            ;;
-        esac
     fi
 
     ac_fn_c_check_header_mongrel "$LINENO" "mmdeviceapi.h" "ac_cv_header_mmdeviceapi_h" "$ac_includes_default"
diff --git a/configure.ac b/configure.ac
index cc2f064..b47c75b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3154,17 +3154,6 @@ AS_HELP_STRING([--enable-directx], [use DirectX for Windows audio/video [[defaul
         AC_CHECK_HEADER(dsound.h, have_dsound=yes)
         AC_CHECK_HEADER(dinput.h, have_dinput=yes)
         AC_CHECK_HEADER(dxgi.h, have_dxgi=yes)
-        AC_CHECK_HEADER(xinput.h, have_xinput=yes)
-        AC_TRY_COMPILE([
-#include <windows.h>
-#include <xinput.h>
-XINPUT_GAMEPAD_EX x1;
-        ],[],[have_xinput_gamepadex=yes])
-        AC_TRY_COMPILE([
-#include <windows.h>
-#include <xinput.h>
-XINPUT_STATE_EX s1;
-        ],[],[have_xinput_stateex=yes])
 
         if test x$have_ddraw = xyes; then
             AC_DEFINE(HAVE_DDRAW_H, 1, [ ])
@@ -3178,15 +3167,6 @@ XINPUT_STATE_EX s1;
         if test x$have_dxgi = xyes; then
             AC_DEFINE(HAVE_DXGI_H, 1, [ ])
         fi
-        if test x$have_xinput = xyes; then
-            AC_DEFINE(HAVE_XINPUT_H, 1, [ ])
-        fi
-        if test x$have_xinput_gamepadex = xyes; then
-            AC_DEFINE(HAVE_XINPUT_GAMEPAD_EX, 1, [ ])
-        fi
-        if test x$have_xinput_stateex = xyes; then
-            AC_DEFINE(HAVE_XINPUT_STATE_EX, 1, [ ])
-        fi
 
         # FIXME: latest Cygwin finds dinput headers, but we die on other win32 headers.
         # FIXME:  ...so force it off for now.
@@ -3197,6 +3177,29 @@ XINPUT_STATE_EX s1;
         esac
     fi
 
+    dnl The following are independent of --enable-directx
+    AC_CHECK_HEADER(xinput.h, have_xinput=yes)
+    AC_TRY_COMPILE([
+#include <windows.h>
+#include <xinput.h>
+XINPUT_GAMEPAD_EX x1;
+        ],[],[have_xinput_gamepadex=yes])
+    AC_TRY_COMPILE([
+#include <windows.h>
+#include <xinput.h>
+XINPUT_STATE_EX s1;
+        ],[],[have_xinput_stateex=yes])
+
+    if test x$have_xinput = xyes; then
+        AC_DEFINE(HAVE_XINPUT_H, 1, [ ])
+    fi
+    if test x$have_xinput_gamepadex = xyes; then
+        AC_DEFINE(HAVE_XINPUT_GAMEPAD_EX, 1, [ ])
+    fi
+    if test x$have_xinput_stateex = xyes; then
+        AC_DEFINE(HAVE_XINPUT_STATE_EX, 1, [ ])
+    fi
+
     AC_CHECK_HEADER(mmdeviceapi.h, have_wasapi=yes)
     if test x$have_wasapi = xyes; then
         AC_DEFINE(HAVE_MMDEVICEAPI_H, 1, [ ])
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 27c67a8..26ed606 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -44,7 +44,9 @@
 #include "../../core/windows/SDL_hid.h"
 #include "../hidapi/SDL_hidapijoystick_c.h"
 
+#ifdef HAVE_XINPUT_H
 #define SDL_JOYSTICK_RAWINPUT_XINPUT
+#endif
 #ifdef SDL_WINDOWS10_SDK
 #define SDL_JOYSTICK_RAWINPUT_WGI
 #endif
@@ -1216,9 +1218,8 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
 {
 #if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT)
     RAWINPUT_DeviceContext *ctx = joystick->hwdata;
-#endif
-
     SDL_bool rumbled = SDL_FALSE;
+#endif
 
 #ifdef SDL_JOYSTICK_RAWINPUT_WGI
     if (!rumbled && ctx->wgi_correlated) {