From 923fe3338a55720ae09eb7a79965f56d4c6850dc Mon Sep 17 00:00:00 2001 From: jolavillette Date: Sat, 20 Jun 2026 17:36:47 +0200 Subject: [PATCH] fix(cmake): reliably prefer Qt6 over Qt5 in GUI detection find_package(QT NAMES Qt6 Qt5 ...) does not honour the NAMES order on distros that ship Qt5 and Qt6 side by side in the same prefix (Debian/ Ubuntu multiarch /usr/lib//cmake): CMake globs the sibling Qt5*/Qt6* config dirs and stops at whichever Config.cmake it reaches first, which is filesystem-order dependent and routinely lands on Qt5 even though Qt6 is listed first. Probe Qt6 explicitly (find_package(Qt6 QUIET COMPONENTS Core)) and fall back to Qt5. This makes the Qt6 preference deterministic and also makes -DCMAKE_DISABLE_FIND_PACKAGE_Qt6=ON work as a reliable Qt5-force switch. Co-Authored-By: Claude Opus 4.8 (1M context) --- retroshare-gui/CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/CMakeLists.txt b/retroshare-gui/CMakeLists.txt index dc4acfdec..db558e270 100644 --- a/retroshare-gui/CMakeLists.txt +++ b/retroshare-gui/CMakeLists.txt @@ -100,7 +100,22 @@ set(CMAKE_AUTOUIC OFF) # Detect Qt6 first, fall back to Qt5. All Qt usage below is version-agnostic via # the ${QT_VERSION_MAJOR} variable so the same tree builds against both. -find_package( QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) +# +# Do NOT use find_package(QT NAMES Qt6 Qt5 ...) here: on distros that ship Qt5 +# and Qt6 side by side in the same prefix (Debian/Ubuntu multiarch, +# /usr/lib//cmake), the NAMES order is NOT honoured. CMake globs the +# sibling Qt5*/Qt6* config dirs and stops at whichever Config.cmake it +# reaches first; that order is filesystem-dependent and routinely picks Qt5 even +# though Qt6 is listed first. We therefore probe Qt6 explicitly and fall back to +# Qt5. Bonus: this makes -DCMAKE_DISABLE_FIND_PACKAGE_Qt6=ON work as a reliable +# way to force a Qt5 build (it didn't, with the versionless QT package name). +find_package( Qt6 QUIET COMPONENTS Core ) +if( Qt6_FOUND ) + set( QT_VERSION_MAJOR 6 ) +else() + find_package( Qt5 COMPONENTS Core REQUIRED ) + set( QT_VERSION_MAJOR 5 ) +endif() find_package( Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Xml Network Multimedia PrintSupport REQUIRED) if(QT_VERSION_MAJOR EQUAL 6)