# The optional runtime-font target: plot::text::TrueTypeFont, which bakes a real
# TrueType/OpenType file into a fixed-cell coverage atlas at run time. It is the
# only target in the project that reaches the vendored third_party/stb_truetype.h,
# and the top-level CMakeLists.txt adds this directory only when PLOT_BUILD_TTF_FONT
# is on -- so plot_core, its public headers and every other target stay
# third-party-free, and a build with the option off neither compiles nor links any
# of it.
#
# Two targets, not one, and for the reason the whole task exists: stb_truetype is
# third-party source, so it is compiled in its own object library to which
# plot_apply_warnings() is *not* applied. The project's warning set stays on our
# own code (and stays clean under it) without a single per-file suppression to
# quiet someone else's header -- see cmake/plot_options.cmake, whose warning
# policy is "never suppressed per file".
add_library(plot_stb_truetype OBJECT stb_truetype_impl.cpp)
# The vendored header's directory is PRIVATE and on this object library alone:
# nothing else in the build can reach stb_truetype.h even by accident, and a
# consumer of the installed target needs none of it (the parser is compiled into
# the archive, so only our own header is on the interface).
target_include_directories(plot_stb_truetype PRIVATE "${CMAKE_SOURCE_DIR}/third_party")
target_compile_features(plot_stb_truetype PRIVATE cxx_std_20)

# The backend itself. Its objects come from the object library above, so the
# archive is self-contained: a consumer links plot::font_ttf and nothing else, and
# no non-exported target leaks into the install set's link interface.
add_library(plot_font_ttf STATIC
  true_type_font.cpp
  $<TARGET_OBJECTS:plot_stb_truetype>)
add_library(plot::font_ttf ALIAS plot_font_ttf)
# The installed tree names it plot::font_ttf, like the build tree (see
# plot_core's EXPORT_NAME).
set_target_properties(plot_font_ttf PROPERTIES EXPORT_NAME font_ttf)

# The public include root is the project's own `include/`, because that is where
# the target's header is reached from: <plot/text/true_type_font.hpp>. The build
# and install interfaces are the same pair plot_core declares, spelled here
# because this target is the one that owns the header.
target_include_directories(plot_font_ttf PUBLIC
  $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)

# PRIVATE, like the object library's: this target's own source includes the
# vendored header for its declarations (the implementation is the object library
# above), and nothing that links plot::font_ttf inherits the path -- a consumer
# needs none of it, because stb_truetype is compiled into the archive.
target_include_directories(plot_font_ttf PRIVATE "${CMAKE_SOURCE_DIR}/third_party")
target_compile_features(plot_font_ttf PUBLIC cxx_std_20)
target_link_libraries(plot_font_ttf PUBLIC plot::core)
plot_apply_warnings(plot_font_ttf)

# It joins the install and export set: it has no dependency a consumer would have
# to re-find (the vendored header is compiled in, and third_party/ is not
# installed at all), so find_package(plot) + target_link_libraries(consumer
# PRIVATE plot::font_ttf) works from an installed prefix whenever the option was
# on -- and plotConfig.cmake then needs no find_dependency() for it. The reason
# string is what the configure log prints.
plot_record_adapter_export(plot_font_ttf TRUE
  "its only third-party dependency is compiled in from third_party/" "")
