From 7313db5ac0bfe2139980d0d7a6d9a5e75754af6c Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 7 Apr 2023 15:53:29 +0200 Subject: [PATCH] Add compile test for QX11Application if Qt was compiled without XCB, globalshortcut-x11 failed to compile. --- CMakeLists.txt | 36 ++++++++++++++++------ src/config.h.in | 2 ++ src/globalshortcuts/globalshortcut-x11.cpp | 10 +++--- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85eb0af8..74884306 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,6 +276,24 @@ if(X11_FOUND) else() message(STATUS "Missing qpa/qplatformnativeinterface.h header.") endif() + + # Check for QX11Application (Qt 6 compiled with XCB). + if(BUILD_WITH_QT6 AND Qt6Gui_VERSION VERSION_GREATER_EQUAL 6.2.0) + set(CMAKE_REQUIRED_FLAGS "-std=c++17") + set(CMAKE_REQUIRED_LIBRARIES ${QtCore_LIBRARIES} ${QtGui_LIBRARIES}) + check_cxx_source_compiles(" + #include + int main() { + (void)qApp->nativeInterface(); + return 0; + } + " + HAVE_QX11APPLICATION + ) + unset(CMAKE_REQUIRED_FLAGS) + unset(CMAKE_REQUIRED_LIBRARIES) + endif() + endif(X11_FOUND) option(USE_TAGLIB "Build with TagLib" OFF) @@ -397,17 +415,13 @@ optional_component(GLOBALSHORTCUTS ON "Global shortcuts" DEPENDS "D-Bus, X11, Windows or macOS" HAVE_GLOBALSHORTCUTS_SUPPORT ) -if(BUILD_WITH_QT6 AND (Qt6Core_VERSION VERSION_EQUAL 6.2.0 OR Qt6Core_VERSION VERSION_GREATER 6.2.0)) - optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" DEPENDS "X11" X11_FOUND) -else() - if(HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) - set(HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H ON) - endif() - optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" - DEPENDS "X11" X11_FOUND - DEPENDS "Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header" HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H - ) +if(HAVE_QX11APPLICATION OR HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) + set(X11_GLOBALSHORTCUTS_REQUIREMENT_FOUND ON) endif() +optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" + DEPENDS "X11" X11_FOUND + DEPENDS "QX11Application, X11Extras or qpa/qplatformnativeinterface.h header" X11_GLOBALSHORTCUTS_REQUIREMENT_FOUND +) optional_component(AUDIOCD ON "Devices: Audio CD support" DEPENDS "libcdio" LIBCDIO_FOUND @@ -510,6 +524,8 @@ if(NOT CMAKE_CROSSCOMPILING) SQLITE_FTS5_TEST ) endif() + unset(CMAKE_REQUIRED_FLAGS) + unset(CMAKE_REQUIRED_LIBRARIES) endif() # Set up definitions diff --git a/src/config.h.in b/src/config.h.in index c8d126b3..7c5659e2 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -55,4 +55,6 @@ #cmakedefine USE_TAGLIB #cmakedefine USE_TAGPARSER +#cmakedefine HAVE_QX11APPLICATION + #endif // CONFIG_H_IN diff --git a/src/globalshortcuts/globalshortcut-x11.cpp b/src/globalshortcuts/globalshortcut-x11.cpp index 44653517..050ade64 100644 --- a/src/globalshortcuts/globalshortcut-x11.cpp +++ b/src/globalshortcuts/globalshortcut-x11.cpp @@ -35,7 +35,7 @@ #include #include -#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) +#ifndef HAVE_QX11APPLICATION # if defined(HAVE_X11EXTRAS) # include # elif defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) @@ -49,7 +49,7 @@ namespace { Display *X11Display() { -#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) // 6.2: Use the new native interface. +#ifdef HAVE_QX11APPLICATION // Qt 6.2: Use the new native interface. if (!qApp) return nullptr; @@ -73,7 +73,7 @@ Display *X11Display() { #else -# error "Missing Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header." +# error "Missing QX11Application, X11Extras or qpa/qplatformnativeinterface.h header." #endif @@ -81,7 +81,7 @@ Display *X11Display() { quint32 AppRootWindow() { -#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) // 6.2: Use the new native interface. +#ifdef HAVE_QX11APPLICATION // Qt 6.2: Use the new native interface. if (QNativeInterface::QX11Application *x11_app = qApp->nativeInterface()) { if (x11_app->display()) { @@ -108,7 +108,7 @@ quint32 AppRootWindow() { #else -# error "Missing Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header." +# error "Missing QX11Application, X11Extras or qpa/qplatformnativeinterface.h header." #endif