From f896e26f593cb87834ef71c4ffd369db0634398b Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 8 Dec 2025 19:38:37 +0100
Subject: [PATCH] tests: find X11 and wayland-client
---
test/CMakeLists.txt | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8b93e754e558d..b126f72f8d8b0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -102,6 +102,21 @@ define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target i
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.")
+if(HAVE_X11)
+ find_package(X11 QUIET)
+ if(NOT TARGET X11::X11)
+ set(HAVE_X11 OFF)
+ endif()
+endif()
+
+if(HAVE_WAYLAND)
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PkgWaylandClient QUIET IMPORTED_TARGET wayland-client)
+ if(NOT TARGET PkgConfig::PkgWaylandClient)
+ set(HAVE_WAYLAND OFF)
+ endif()
+endif()
+
function(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;THREADS;MAIN_CALLBACKS;NOTRACKMEM" "" "DEPENDS;DISABLE_THREADS_ARGS;NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;INSTALLED_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
@@ -338,15 +353,15 @@ elseif(HAVE_X11 OR HAVE_WAYLAND)
add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c)
if(HAVE_X11)
target_sources(testnative PRIVATE testnativex11.c)
- target_link_libraries(testnative PRIVATE X11)
+ target_link_libraries(testnative PRIVATE X11::X11)
endif()
if(HAVE_WAYLAND)
set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1)
- target_sources(testnative PRIVATE testnativewayland.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c)
+ target_sources(testnative PRIVATE testnativewayland.c "${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c")
# Needed to silence the documentation warning in the generated header file
target_compile_options(testnative PRIVATE -Wno-documentation-unknown-command)
- target_link_libraries(testnative PRIVATE wayland-client)
+ target_link_libraries(testnative PRIVATE PkgConfig::PkgWaylandClient)
endif ()
endif()
@@ -452,7 +467,7 @@ if (HAVE_WAYLAND)
add_sdl_test_executable(testwaylandcustom NEEDS_RESOURCES SOURCES testwaylandcustom.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c)
# Needed to silence the documentation warning in the generated header file
target_compile_options(testwaylandcustom PRIVATE -Wno-documentation-unknown-command)
- target_link_libraries(testwaylandcustom PRIVATE wayland-client)
+ target_link_libraries(testwaylandcustom PRIVATE PkgConfig::PkgWaylandClient)
endif()
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)