diff --git a/build/cmake/modules/FindGTK3.cmake b/build/cmake/modules/FindGTK3.cmake index 5c35029a81..8fee6f9f41 100644 --- a/build/cmake/modules/FindGTK3.cmake +++ b/build/cmake/modules/FindGTK3.cmake @@ -46,5 +46,6 @@ endif () include(CheckSymbolExists) set(CMAKE_REQUIRED_INCLUDES ${GTK3_INCLUDE_DIRS}) check_symbol_exists(GDK_WINDOWING_WAYLAND "gdk/gdk.h" wxHAVE_GDK_WAYLAND) +check_symbol_exists(GDK_WINDOWING_X11 "gdk/gdk.h" wxHAVE_GDK_X11) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK3 DEFAULT_MSG GTK3_INCLUDE_DIRS GTK3_LIBRARIES VERSION_OK) diff --git a/build/cmake/toolkit.cmake b/build/cmake/toolkit.cmake index 577d3c8661..bcbbd75491 100644 --- a/build/cmake/toolkit.cmake +++ b/build/cmake/toolkit.cmake @@ -69,12 +69,6 @@ set(wxTOOLKIT_INCLUDE_DIRS) set(wxTOOLKIT_LIBRARIES) set(wxTOOLKIT_VERSION) -if(UNIX AND NOT APPLE AND NOT WIN32) - find_package(X11 REQUIRED) - list(APPEND wxTOOLKIT_INCLUDE_DIRS ${X11_INCLUDE_DIR}) - list(APPEND wxTOOLKIT_LIBRARIES ${X11_LIBRARIES}) -endif() - if(WXGTK) if(WXGTK4) set(gtk_lib GTK4) @@ -121,6 +115,15 @@ if(WXGTK) endif() endif() +# We need X11 for non-GTK Unix ports (X11, Motif) and for GTK with X11 +# support, but not for Wayland-only GTK (which is why we have to do this after +# find_package(GTKx) above, as this is what sets wxHAVE_GDK_X11). +if(UNIX AND NOT APPLE AND NOT WIN32 AND (WXX11 OR WXMOTIF OR (WXGTK AND wxHAVE_GDK_X11))) + find_package(X11 REQUIRED) + list(APPEND wxTOOLKIT_INCLUDE_DIRS ${X11_INCLUDE_DIR}) + list(APPEND wxTOOLKIT_LIBRARIES ${X11_LIBRARIES}) +endif() + if(WXQT) set(QT_COMPONENTS Core Widgets Gui OpenGL Test) foreach(QT_COMPONENT ${QT_COMPONENTS})