Files

57 lines
2.8 KiB
CMake

# The Qt6 adapter: a QOpenGLWidget that renders a plot into its own framebuffer
# and drives it from Qt's events. It is the third host, and the first whose
# toolkit already owns a GL widget -- so the interesting parts are the surface
# format the application must have set before the widget exists (documented on
# the class) and the device-pixel-ratio mapping between Qt's logical coordinates
# and the framebuffer pixels the library speaks.
#
# Unlike the GLFW and ImGui adapters this one is not fetched: Qt is a system SDK,
# and a project that enables this target is asking for the installed one.
find_package(Qt6 QUIET COMPONENTS Core Gui Widgets OpenGLWidgets)
if(NOT Qt6_FOUND)
message(FATAL_ERROR
"plot: PLOT_BUILD_QT6 is ON but Qt6 was not found (need the Core, Gui, Widgets"
" and OpenGLWidgets components). Install Qt6 -- on Arch, qt6-base -- or"
" configure with -DPLOT_BUILD_QT6=OFF, or point CMAKE_PREFIX_PATH at the Qt6"
" installation.")
endif()
add_library(plot_qt6 STATIC qt_plot_widget.cpp qt_plot_widget.hpp)
add_library(plot::qt6 ALIAS plot_qt6)
# The installed tree names it plot::qt6, like the build tree (see plot_core's).
set_target_properties(plot_qt6 PROPERTIES EXPORT_NAME qt6)
# The public include root is `adapters/`, so the header is reached as
# <qt6/qt_plot_widget.hpp> -- the toolkit's name first, like every other adapter's.
# The build interface is that root; the install one is the prefix's `include`,
# where both headers are installed as <qt6/...> -- the same spelling. The pointer
# anchor in qt_pointer.hpp is internal API, but it still ships: the widget's header
# includes it, so a consumer that gets one without the other does not compile.
target_include_directories(plot_qt6 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>)
# Qt is PUBLIC, unlike GLFW and ImGui: the widget's header derives from
# QOpenGLWidget, so a consumer needs Qt's headers and libraries to use it at all.
target_link_libraries(plot_qt6 PUBLIC
plot::core
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::OpenGLWidgets)
# The widget declares Q_OBJECT, so its header has to go through moc. The property
# is set on this target rather than globally: no other target in the project has a
# Qt class in it, and AUTOMOC scans every source of a target it is set on.
set_target_properties(plot_qt6 PROPERTIES AUTOMOC ON)
plot_apply_warnings(plot_qt6)
# Qt is a system SDK found with find_package() -- a missing Qt6 is a configure
# error above, never a fetch -- so the installed config file can re-find it with
# the same components and the widget's public Qt link interface is satisfiable.
plot_record_adapter_export(plot_qt6 TRUE "Qt6 was resolved by find_package"
"find_dependency(Qt6 COMPONENTS Core Gui Widgets OpenGLWidgets)\n")
if(PLOT_INSTALL)
install(FILES qt_plot_widget.hpp qt_pointer.hpp DESTINATION include/qt6)
endif()