sdl2-compat: Support latest QNX driver. (#626)

From e3de91ff960c7bbf9a1ea07b730bd7d88ae4dfe8 Mon Sep 17 00:00:00 2001
From: eleir9268 <[EMAIL REDACTED]>
Date: Thu, 24 Sep 2026 14:05:56 -0400
Subject: [PATCH] Support latest QNX driver. (#626)

Co-authored-by: Martin Krastev <mkrastev@qnx.com>
---
 CMakeLists.txt                       |  4 ++--
 include/SDL2/SDL_config_unix.h.cmake | 13 +++++++++++++
 src/dynapi/SDL_dynapi.c              |  2 +-
 src/sdl2_compat.c                    |  6 +++++-
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e793c2ce..075d412c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,8 +93,8 @@ set(SDL2COMPAT_VENDOR_INFO "" CACHE STRING "Vendor name and/or version to add to
 set(SDL2COMPAT_FRAMEWORK FALSE)
 #FIXME: should SDL2-compat modify vendor_info/revision information?
 
-if(SDL2COMPAT_STATIC AND NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
-  message(FATAL_ERROR "Static builds are only supported on Linux.")
+if(SDL2COMPAT_STATIC AND NOT (CMAKE_SYSTEM_NAME MATCHES "Linux|QNX"))
+  message(FATAL_ERROR "Static builds are only supported on Linux or QNX.")
 endif()
 
 macro(check_add_debug_flag FLAG SUFFIX)
diff --git a/include/SDL2/SDL_config_unix.h.cmake b/include/SDL2/SDL_config_unix.h.cmake
index fa315095..166900ac 100644
--- a/include/SDL2/SDL_config_unix.h.cmake
+++ b/include/SDL2/SDL_config_unix.h.cmake
@@ -270,4 +270,17 @@
 #define SDL_VIDEO_VULKAN 1
 #endif
 
+/* Enable QNX desktop environment */
+#if defined(__QNX__)
+#define SDL_VIDEO_DRIVER_WAYLAND 1
+#define SDL_VIDEO_DRIVER_QNX 1
+#endif
+
+/* Enable QNX audio */
+#if defined(__QNX__) && (__QNX__ >= 800)
+#define SDL_AUDIO_DRIVER_ALSA 1
+#elif defined(__QNX__)
+#define SDL_AUDIO_DRIVER_QNX 1
+#endif
+
 #endif /* SDL_config_unix_h_ */
diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index 9c88c6d2..eb187fda 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -379,7 +379,7 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
     return retval;
 }
 
-#elif defined(unix) || defined(__unix__) || defined(__APPLE__) || defined(SDL_PLATFORM_HAIKU) || defined(SDL_PLATFORM_QNX)
+#elif defined(unix) || defined(__unix__) || defined(__APPLE__) || defined(SDL_PLATFORM_HAIKU) || defined(SDL_PLATFORM_QNXNTO)
 #include <stdio.h>
 #include <stdlib.h>
 #include <dlfcn.h>
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 2ecc7772..e7f3c662 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -100,6 +100,10 @@ This breaks the build when creating SDL_ ## DisableScreenSaver
 #include <unistd.h> /* for readlink() */
 #endif
 
+#ifdef SDL_PLATFORM_QNXNTO
+#include <sys/process.h> /* for getprogname() */
+#endif
+
 #if defined(SDL_PLATFORM_UNIX) || defined(__APPLE__)
 #ifndef PATH_MAX
 #define PATH_MAX 1024
@@ -631,7 +635,7 @@ static void OS_GetExeName(char *buf, const unsigned maxpath, bool *use_base_path
     buf[0] = '\0';
     GetModuleFileNameA(NULL, buf, maxpath);
 }
-#elif defined(__APPLE__) || defined(SDL_PLATFORM_FREEBSD)
+#elif defined(__APPLE__) || defined(SDL_PLATFORM_FREEBSD) || defined(SDL_PLATFORM_QNXNTO)
 static void OS_GetExeName(char *buf, const unsigned maxpath, bool *use_base_path)
 {
     const char *progname = getprogname();