Skip to content

Commit fe856ea

Browse files
committed
support headless qt for CI and CLI modes of use, but not by default
if GUI mode is not supported, build fails with diagnostic info. re-running with QT_ALLOW_HEADLESS lets the build continue with whatever Qt defaults to. means we also no longer force the -xcb option, which was causing build failures irrelevant at the time due to missing some xcb and xkb devel packages on rhel. this generalized result should give us fair warning on all the major platforms if there's an issue.
1 parent b171adc commit fe856ea

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

qt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(ENABLE_QT "${ENABLE_QT}" CACHE BOOL "Enable Qt6 build")
1717

1818
if (ENABLE_QT)
1919

20+
option(QT_ALLOW_HEADLESS "Allow building Qt without a window-capable platform plugin" OFF)
21+
2022
git_submodule_init(qt qtbase/configure)
2123

2224
RegisterDeps(Qt6)

qt/qt_config.cmake.in

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ endif (NOT WIN32)
1919
# https://doc.qt.io/qt-6/configure-options.html
2020
set(CONFIG_EXTRA_OPTS ${CONFIG_EXTRA_OPTS} -qt-zlib -qt-libpng)
2121

22-
# If we can't compile Qt with XCB on X11 platforms, we want a fatal error -
23-
# a non-GUI Qt build isn't helpful
24-
if (NOT APPLE AND NOT WIN32)
25-
set(CONFIG_EXTRA_OPTS ${CONFIG_EXTRA_OPTS} -xcb)
26-
endif (NOT APPLE AND NOT WIN32)
27-
2822
if ("${CMAKE_BUILD_TYPE}" STREQUAL "" OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
2923
set(QT_CONFIG_OPTS "-debug")
3024
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
@@ -39,6 +33,66 @@ if (QT_RET)
3933
message(FATAL_ERROR "Qt configure failed: ${MSG}\n")
4034
endif (QT_RET)
4135

36+
# See if we are building sans GUI, requires defining QT_ALLOW_HEADLESS
37+
#
38+
# Normalize: check cmake or env var for setting.
39+
if (NOT DEFINED QT_ALLOW_HEADLESS AND DEFINED ENV{QT_ALLOW_HEADLESS})
40+
set(QT_ALLOW_HEADLESS "$ENV{QT_ALLOW_HEADLESS}")
41+
endif()
42+
43+
# Read a cache bool from Qt's build cache
44+
set(qt_cache "@QT_BUILD_DIR@/CMakeCache.txt")
45+
macro(qt_cache_check NAME OUT)
46+
if (EXISTS "${qt_cache}")
47+
file(STRINGS "${qt_cache}" _line REGEX "^${NAME}:[^=]*=")
48+
if (_line)
49+
string(REGEX REPLACE "^[^=]*=" "" _val "${_line}")
50+
set(${OUT} "${_val}")
51+
else()
52+
set(${OUT} "")
53+
endif()
54+
else()
55+
set(${OUT} "")
56+
endif()
57+
endmacro()
58+
59+
# check GUI module + platform backends
60+
qt_cache_check("FEATURE_gui" feature_gui)
61+
qt_cache_check("FEATURE_xcb" feature_xcb)
62+
qt_cache_check("FEATURE_wayland_client" feature_wayland)
63+
qt_cache_check("FEATURE_windows" feature_windows)
64+
qt_cache_check("FEATURE_cocoa" feature_cocoa)
65+
66+
# does a window-capable backend exists for this host OS?
67+
set(qt_has_window_gui OFF)
68+
if (feature_gui STREQUAL "ON")
69+
if (WIN32 AND feature_windows STREQUAL "ON")
70+
set(qt_has_window_gui ON)
71+
elseif (APPLE AND feature_cocoa STREQUAL "ON")
72+
set(qt_has_window_gui ON)
73+
elseif (UNIX AND NOT APPLE AND (feature_xcb STREQUAL "ON" OR feature_wayland STREQUAL "ON"))
74+
set(qt_has_window_gui ON)
75+
endif()
76+
endif()
77+
78+
# fail if no GUI by default; allow explicit override with the QT_ALLOW_HEADLESS switch.
79+
if (feature_gui STREQUAL "ON" AND NOT qt_has_window_gui AND NOT QT_ALLOW_HEADLESS)
80+
message(FATAL_ERROR
81+
"\nQt GUI configured (QT_FEATURE_gui=ON) but no window-capable platform plugin is enabled.\n"
82+
"Detected:\n"
83+
" FEATURE_xcb=${feature_xcb}\n"
84+
" FEATURE_wayland_client=${feature_wayland}\n"
85+
" FEATURE_cocoa=${feature_cocoa}\n"
86+
" FEATURE_windows=${feature_windows}\n\n"
87+
"To proceed headless (e.g., offscreen/minimal/vnc), set QT_ALLOW_HEADLESS=ON\n")
88+
elseif (feature_gui STREQUAL "ON" AND NOT qt_has_window_gui AND QT_ALLOW_HEADLESS)
89+
message(WARNING
90+
"Proceeding without a window-capable Qt backend (headless).\n"
91+
"Only minimal/offscreen/eglfs/linuxfb/vnc are expected.")
92+
else()
93+
message(STATUS "Qt platform backend check: OK (window-capable backend present).")
94+
endif()
95+
4296
message("Qt configure succeeded: ${MSG}\n")
4397

4498
# Local Variables:

0 commit comments

Comments
 (0)