Files

44 lines
2.2 KiB
CMake

# The GLFW adapter: the reference host for the library. It owns the window, the
# context and the loop, and translates GLFW's events into plot::input events.
#
# GLFW is resolved by the shared plot_find_glfw() (cmake/plot_options.cmake), so a
# build that also enables the Dear ImGui adapter -- which needs GLFW for
# imgui_impl_glfw -- discovers (and at worst fetches) a single copy.
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.
# 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()