feat(build): install/export rules, umbrella header, verified consumer
This commit is contained in:
1 parent
377cca8e9b
commit
0972903d27
11 files changed
+333
-7
No files matched your search
@@ -8,10 +8,36 @@ plot_find_glfw(plot_glfw_dep)
|
||||
|
||||
add_library(plot_glfw STATIC glfw_host.cpp)
|
||||
add_library(plot::glfw ALIAS plot_glfw)
|
||||
# The installed tree names it plot::glfw, like the build tree (see plot_core's).
|
||||
set_target_properties(plot_glfw PROPERTIES EXPORT_NAME glfw)
|
||||
|
||||
# The public include root is `adapters/`, so the header is reached as
|
||||
# <glfw/glfw_host.hpp> -- the toolkit's name first, like every other adapter's.
|
||||
target_include_directories(plot_glfw PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
# The build interface is that root; the install one is the prefix's `include`,
|
||||
# where glfw_host.hpp is installed as <glfw/glfw_host.hpp>, the same spelling.
|
||||
target_include_directories(plot_glfw PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
# GLFW stays PRIVATE: the header forward-declares GLFWwindow and includes no GLFW
|
||||
# header, so a consumer of plot::glfw does not inherit the toolkit.
|
||||
target_link_libraries(plot_glfw PUBLIC plot::core PRIVATE ${plot_glfw_dep})
|
||||
plot_apply_warnings(plot_glfw)
|
||||
|
||||
# PLOT_GLFW_DEP is either a target find_package()/pkg-config created or one
|
||||
# FetchContent built. The first two can be promised to a consumer -- the installed
|
||||
# config file re-runs the very same discovery -- but a fetched GLFW cannot: there
|
||||
# is no glfw3Config.cmake on the consumer's machine to find, so exporting this
|
||||
# adapter would hand out a target its link interface cannot satisfy. In that case
|
||||
# the adapter is not installed at all.
|
||||
plot_glfw_dependency_snippet(plot_glfw_dependency)
|
||||
if(PLOT_GLFW_DEP_ORIGIN STREQUAL "FetchContent")
|
||||
plot_record_adapter_export(plot_glfw FALSE
|
||||
"GLFW was fetched with FetchContent, so a consumer's find_package(plot) cannot re-find it" "")
|
||||
else()
|
||||
plot_record_adapter_export(plot_glfw TRUE
|
||||
"GLFW was resolved by ${PLOT_GLFW_DEP_ORIGIN}" "${plot_glfw_dependency}")
|
||||
if(PLOT_INSTALL)
|
||||
install(FILES glfw_host.hpp DESTINATION include/glfw)
|
||||
endif()
|
||||
endif()
|
||||
@@ -22,13 +22,33 @@ endif()
|
||||
|
||||
add_library(plot_gtk4 STATIC gtk_plot_area.cpp gtk_plot_area.hpp gtk_input.hpp)
|
||||
add_library(plot::gtk4 ALIAS plot_gtk4)
|
||||
# The installed tree names it plot::gtk4, like the build tree (see plot_core's).
|
||||
set_target_properties(plot_gtk4 PROPERTIES EXPORT_NAME gtk4)
|
||||
|
||||
# The public include root is `adapters/`, so the headers are reached as
|
||||
# <gtk4/gtk_plot_area.hpp> and <gtk4/gtk_input.hpp> -- the toolkit's name first,
|
||||
# like every other adapter's.
|
||||
target_include_directories(plot_gtk4 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
# like every other adapter's. The build interface is that root; the install one is
|
||||
# the prefix's `include`, where both are installed under `gtk4/`, the same
|
||||
# spelling.
|
||||
target_include_directories(plot_gtk4 PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
# GTK is PUBLIC, unlike GLFW and ImGui: the adapter's factory hands out a
|
||||
# GtkWidget, so a consumer that embeds the area needs GTK's headers and libraries
|
||||
# to put it anywhere -- the widget *is* the toolkit's object -- and GTK's include
|
||||
# directory is not one the compiler searches by default.
|
||||
target_link_libraries(plot_gtk4 PUBLIC plot::core PkgConfig::GTK4_PC)
|
||||
plot_apply_warnings(plot_gtk4)
|
||||
|
||||
# GTK came from pkg-config, which the installed config file can re-run: the
|
||||
# snippet re-creates the exact PkgConfig::GTK4_PC target the adapter's public link
|
||||
# interface names, so a consumer that links plot::gtk4 gets GTK's own include
|
||||
# directories and libraries the same way this build did.
|
||||
plot_record_adapter_export(plot_gtk4 TRUE "GTK4 was resolved by pkg-config"
|
||||
"find_dependency(PkgConfig)\npkg_check_modules(GTK4_PC REQUIRED IMPORTED_TARGET gtk4)\n")
|
||||
if(PLOT_INSTALL)
|
||||
# gtk_input.hpp is installed with the public header: the demo and the test suite
|
||||
# reach it as <gtk4/gtk_input.hpp>, and it is a toolkit-free header a consumer
|
||||
# can use without GTK.
|
||||
install(FILES gtk_plot_area.hpp gtk_input.hpp DESTINATION include/gtk4)
|
||||
endif()
|
||||
@@ -52,3 +52,12 @@ target_include_directories(plot_imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
# consumer of plot::imgui does not inherit the toolkit's headers.
|
||||
target_link_libraries(plot_imgui PUBLIC plot::core PRIVATE imgui ${plot_imgui_glfw_dep})
|
||||
plot_apply_warnings(plot_imgui)
|
||||
|
||||
# Not installed and not exported, and not because of a discovery fallback: ImGui
|
||||
# is *always* fetched here, so there is no ImGui package for an installed config
|
||||
# file to find. Exporting plot::imgui would name the fetched `imgui` target in its
|
||||
# link interface and leave every consumer of `find_package(plot)` unable to
|
||||
# configure -- so plot::imgui is a build-tree target only, and a consumer that
|
||||
# wants it adds the adapter's source or fetches the same pinned tag itself.
|
||||
plot_record_adapter_export(plot_imgui FALSE
|
||||
"ImGui is supplied by FetchContent, so find_package(plot) cannot promise it to a consumer" "")
|
||||
@@ -19,9 +19,19 @@ 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.
|
||||
target_include_directories(plot_qt6 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
# 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
|
||||
@@ -35,3 +45,12 @@ target_link_libraries(plot_qt6 PUBLIC
|
||||
# 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()
|
||||
Reference in new issue
Block a user