From a38cd7a067e2a7e6be07e98e925759f36d019912 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 7 Aug 2024 16:57:53 -0700
Subject: [PATCH] Added checks for GameInput.h to the build system
---
CMakeLists.txt | 29 ++++++++++++++-----
include/build_config/SDL_build_config.h.cmake | 24 ++++++++-------
.../build_config/SDL_build_config_windows.h | 7 ++++-
.../build_config/SDL_build_config_wingdk.h | 14 ++-------
include/build_config/SDL_build_config_xbox.h | 14 +--------
src/video/windows/SDL_windowsgameinput.c | 4 ---
6 files changed, 43 insertions(+), 49 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca5e5f07408c7..083cbd696c70f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1870,14 +1870,23 @@ elseif(WINDOWS)
#include <windows.h>
#include <xinput.h>
int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_H)
- check_c_source_compiles("
- #define COBJMACROS
- #include <windows.gaming.input.h>
- __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2 *s2;
- int main(int argc, char **argv) { return 0; }" HAVE_WINDOWS_GAMING_INPUT_H)
endif()
# headers needed elsewhere
+ check_c_source_compiles("
+ #define COBJMACROS
+ #include <windows.gaming.input.h>
+ static __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2 *s2;
+ int main(int argc, char **argv) { return 0; }" HAVE_WINDOWS_GAMING_INPUT_H
+ )
+ check_c_source_compiles("
+ #include <stdbool.h>
+ #define COBJMACROS
+ #include <GameInput.h>
+ // Requires Windows SDK version 10.0.26100.0 or newer
+ static GameInputSystemButtons s = GameInputSystemButtonNone;
+ int main(int argc, char **argv) { return 0; }" HAVE_GAMEINPUT_H
+ )
check_include_file(dxgi1_6.h HAVE_DXGI1_6_H)
check_include_file(tpcshrd.h HAVE_TPCSHRD_H)
check_include_file(roapi.h HAVE_ROAPI_H)
@@ -2084,9 +2093,13 @@ elseif(WINDOWS)
set(SDL_JOYSTICK_XINPUT 1)
set(HAVE_XINPUT TRUE)
endif()
- if(HAVE_WINDOWS_GAMING_INPUT_H)
- set(SDL_JOYSTICK_WGI 1)
- endif()
+ endif()
+ if(HAVE_WINDOWS_GAMING_INPUT_H)
+ set(SDL_JOYSTICK_WGI 1)
+ endif()
+ if(HAVE_GAMEINPUT_H)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/gdk/*.c")
+ set(SDL_JOYSTICK_GAMEINPUT 1)
endif()
set(HAVE_SDL_JOYSTICK TRUE)
diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake
index 1e0cdc9db550b..74e4479ab9385 100644
--- a/include/build_config/SDL_build_config.h.cmake
+++ b/include/build_config/SDL_build_config.h.cmake
@@ -232,6 +232,7 @@
#cmakedefine HAVE_DINPUT_H @HAVE_DINPUT_H@
#cmakedefine HAVE_XINPUT_H @HAVE_XINPUT_H@
#cmakedefine HAVE_WINDOWS_GAMING_INPUT_H @HAVE_WINDOWS_GAMING_INPUT_H@
+#cmakedefine HAVE_GAMEINPUT_H @HAVE_GAMEINPUT_H@
#cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@
#cmakedefine HAVE_DXGI1_6_H @HAVE_DXGI1_6_H@
@@ -294,25 +295,26 @@
#cmakedefine SDL_INPUT_LINUXKD @SDL_INPUT_LINUXKD@
#cmakedefine SDL_INPUT_FBSDKBIO @SDL_INPUT_FBSDKBIO@
#cmakedefine SDL_INPUT_WSCONS @SDL_INPUT_WSCONS@
+#cmakedefine SDL_HAVE_MACHINE_JOYSTICK_H @SDL_HAVE_MACHINE_JOYSTICK_H@
#cmakedefine SDL_JOYSTICK_ANDROID @SDL_JOYSTICK_ANDROID@
-#cmakedefine SDL_JOYSTICK_HAIKU @SDL_JOYSTICK_HAIKU@
-#cmakedefine SDL_JOYSTICK_WGI @SDL_JOYSTICK_WGI@
#cmakedefine SDL_JOYSTICK_DINPUT @SDL_JOYSTICK_DINPUT@
-#cmakedefine SDL_JOYSTICK_XINPUT @SDL_JOYSTICK_XINPUT@
#cmakedefine SDL_JOYSTICK_DUMMY @SDL_JOYSTICK_DUMMY@
+#cmakedefine SDL_JOYSTICK_EMSCRIPTEN @SDL_JOYSTICK_EMSCRIPTEN@
+#cmakedefine SDL_JOYSTICK_GAMEINPUT @SDL_JOYSTICK_GAMEINPUT@
+#cmakedefine SDL_JOYSTICK_HAIKU @SDL_JOYSTICK_HAIKU@
+#cmakedefine SDL_JOYSTICK_HIDAPI @SDL_JOYSTICK_HIDAPI@
#cmakedefine SDL_JOYSTICK_IOKIT @SDL_JOYSTICK_IOKIT@
-#cmakedefine SDL_JOYSTICK_MFI @SDL_JOYSTICK_MFI@
#cmakedefine SDL_JOYSTICK_LINUX @SDL_JOYSTICK_LINUX@
-#cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@
-#cmakedefine SDL_HAVE_MACHINE_JOYSTICK_H @SDL_HAVE_MACHINE_JOYSTICK_H@
-#cmakedefine SDL_JOYSTICK_HIDAPI @SDL_JOYSTICK_HIDAPI@
+#cmakedefine SDL_JOYSTICK_MFI @SDL_JOYSTICK_MFI@
+#cmakedefine SDL_JOYSTICK_N3DS @SDL_JOYSTICK_N3DS@
+#cmakedefine SDL_JOYSTICK_PS2 @SDL_JOYSTICK_PS2@
+#cmakedefine SDL_JOYSTICK_PSP @SDL_JOYSTICK_PSP@
#cmakedefine SDL_JOYSTICK_RAWINPUT @SDL_JOYSTICK_RAWINPUT@
-#cmakedefine SDL_JOYSTICK_EMSCRIPTEN @SDL_JOYSTICK_EMSCRIPTEN@
+#cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@
#cmakedefine SDL_JOYSTICK_VIRTUAL @SDL_JOYSTICK_VIRTUAL@
#cmakedefine SDL_JOYSTICK_VITA @SDL_JOYSTICK_VITA@
-#cmakedefine SDL_JOYSTICK_PSP @SDL_JOYSTICK_PSP@
-#cmakedefine SDL_JOYSTICK_PS2 @SDL_JOYSTICK_PS2@
-#cmakedefine SDL_JOYSTICK_N3DS @SDL_JOYSTICK_N3DS@
+#cmakedefine SDL_JOYSTICK_WGI @SDL_JOYSTICK_WGI@
+#cmakedefine SDL_JOYSTICK_XINPUT @SDL_JOYSTICK_XINPUT@
#cmakedefine SDL_HAPTIC_DUMMY @SDL_HAPTIC_DUMMY@
#cmakedefine SDL_HAPTIC_LINUX @SDL_HAPTIC_LINUX@
#cmakedefine SDL_HAPTIC_IOKIT @SDL_HAPTIC_IOKIT@
diff --git a/include/build_config/SDL_build_config_windows.h b/include/build_config/SDL_build_config_windows.h
index 6feab76aa82a2..9158ddbf3ed3c 100644
--- a/include/build_config/SDL_build_config_windows.h
+++ b/include/build_config/SDL_build_config_windows.h
@@ -100,6 +100,9 @@ typedef unsigned int uintptr_t;
#define HAVE_AUDIOCLIENT_H 1
#define HAVE_TPCSHRD_H 1
#define HAVE_SENSORSAPI_H 1
+#if defined(__has_include) && __has_include(<GameInput.h>)
+#define HAVE_GAMEINPUT_H 1
+#endif
#if (defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)) && (defined(_MSC_VER) && _MSC_VER >= 1600)
#elif defined(__has_include) && (defined(__i386__) || defined(__x86_64))
# if !__has_include(<immintrin.h>)
@@ -233,7 +236,9 @@ typedef unsigned int uintptr_t;
/* Enable various input drivers */
#define SDL_JOYSTICK_DINPUT 1
-/*#define SDL_JOYSTICK_GAMEINPUT 1*/
+#ifdef HAVE_GAMEINPUT_H
+#define SDL_JOYSTICK_GAMEINPUT 1
+#endif
#define SDL_JOYSTICK_HIDAPI 1
#ifndef SDL_PLATFORM_WINRT
#define SDL_JOYSTICK_RAWINPUT 1
diff --git a/include/build_config/SDL_build_config_wingdk.h b/include/build_config/SDL_build_config_wingdk.h
index e46c4593f9332..859b606e8ae2f 100644
--- a/include/build_config/SDL_build_config_wingdk.h
+++ b/include/build_config/SDL_build_config_wingdk.h
@@ -47,6 +47,7 @@
#define HAVE_AUDIOCLIENT_H 1
#define HAVE_TPCSHRD_H 1
#define HAVE_SENSORSAPI_H 1
+#define HAVE_GAMEINPUT_H 1
#if (defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)) && (defined(_MSC_VER) && _MSC_VER >= 1600)
#elif defined(__has_include) && (defined(__i386__) || defined(__x86_64))
# if !__has_include(<immintrin.h>)
@@ -164,25 +165,14 @@
/* Enable various input drivers */
#define SDL_JOYSTICK_DINPUT 1
+#define SDL_JOYSTICK_GAMEINPUT 1
#define SDL_JOYSTICK_HIDAPI 1
#define SDL_JOYSTICK_RAWINPUT 1
#define SDL_JOYSTICK_VIRTUAL 1
-#ifdef HAVE_WINDOWS_GAMING_INPUT_H
#define SDL_JOYSTICK_WGI 1
-#endif
#define SDL_JOYSTICK_XINPUT 1
#define SDL_HAPTIC_DINPUT 1
-/* Native GameInput: */
-/*#define SDL_JOYSTICK_GAMEINPUT 1*/
-#if defined(SDL_JOYSTICK_GAMEINPUT) && (defined(SDL_JOYSTICK_XINPUT) || defined(SDL_JOYSTICK_DINPUT))
-#error "GameInput cannot co-exist, choose one."
-#endif /* defined(SDL_JOYSTICK_GAMEINPUT) && (defined(SDL_JOYSTICK_XINPUT) || defined(SDL_JOYSTICK_DINPUT)) */
-#if defined(SDL_JOYSTICK_GAMEINPUT) && SDL_JOYSTICK_GAMEINPUT
-/* TODO: Implement proper haptics for GameInput! */
-#define SDL_HAPTIC_DUMMY 1
-#endif /* defined(SDL_JOYSTICK_GAMEINPUT) && SDL_JOYSTICK_GAMEINPUT */
-
/* Enable the sensor driver */
#ifdef HAVE_SENSORSAPI_H
#define SDL_SENSOR_WINDOWS 1
diff --git a/include/build_config/SDL_build_config_xbox.h b/include/build_config/SDL_build_config_xbox.h
index 7bba464324931..0ff0ded83b9e2 100644
--- a/include/build_config/SDL_build_config_xbox.h
+++ b/include/build_config/SDL_build_config_xbox.h
@@ -46,6 +46,7 @@
#define HAVE_AUDIOCLIENT_H 1
/*#define HAVE_TPCSHRD_H 1*/
/*#define HAVE_SENSORSAPI_H 1*/
+#define HAVE_GAMEINPUT_H 1
#if (defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)) && (defined(_MSC_VER) && _MSC_VER >= 1600)
#elif defined(__has_include) && (defined(__i386__) || defined(__x86_64))
# if !__has_include(<immintrin.h>)
@@ -162,25 +163,12 @@
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various input drivers */
-/*#define SDL_JOYSTICK_DINPUT 1*/
-/*#define SDL_JOYSTICK_HIDAPI 1*/
-/*#define SDL_JOYSTICK_RAWINPUT 1*/
#define SDL_JOYSTICK_VIRTUAL 1
-#ifdef HAVE_WINDOWS_GAMING_INPUT_H
-#define SDL_JOYSTICK_WGI 1
-#endif
/* This is XInputOnGameInput for GDK platforms: */
/*#define SDL_JOYSTICK_XINPUT 1*/
/* Native GameInput: */
#define SDL_JOYSTICK_GAMEINPUT 1
-#if defined(SDL_JOYSTICK_GAMEINPUT) && (defined(SDL_JOYSTICK_XINPUT) || defined(SDL_JOYSTICK_DINPUT))
-#error "GameInput cannot co-exist, choose one."
-#endif /* defined(SDL_JOYSTICK_GAMEINPUT) && (defined(SDL_JOYSTICK_XINPUT) || defined(SDL_JOYSTICK_DINPUT)) */
-#if defined(SDL_JOYSTICK_GAMEINPUT) && SDL_JOYSTICK_GAMEINPUT
-/* TODO: Implement proper haptics for GameInput! */
#define SDL_HAPTIC_DUMMY 1
-#endif /* defined(SDL_JOYSTICK_GAMEINPUT) && SDL_JOYSTICK_GAMEINPUT */
-/*#define SDL_HAPTIC_DINPUT 1*/
/* Enable the sensor driver */
#ifdef HAVE_SENSORSAPI_H
diff --git a/src/video/windows/SDL_windowsgameinput.c b/src/video/windows/SDL_windowsgameinput.c
index d92eb27cdd7ed..e36eb7efd2f8d 100644
--- a/src/video/windows/SDL_windowsgameinput.c
+++ b/src/video/windows/SDL_windowsgameinput.c
@@ -22,10 +22,6 @@
#include "SDL_windowsvideo.h"
-#if defined(__has_include) && __has_include(<GameInput.h>)
-#define HAVE_GAMEINPUT_H
-#endif
-
#ifdef HAVE_GAMEINPUT_H
#include <stdbool.h>