# Keeps include/plot/plot.hpp honest against the plan's Global Constraints: # every public header under include/plot/ must be included by the umbrella, and # every the umbrella names must be a file that actually exists. # # "Public" is everything the recursive glob finds except the macro-gated # */detail/ instrumentation, which is documented as not part of the surface and # deliberately stays out of the umbrella. # # Runs twice: tests/CMakeLists.txt includes it at configure time (so a header # added without its umbrella line stops the configure rather than the run), and # ctest runs it again as `plot_umbrella_covers_public_headers` via `cmake -P`. # Both read the same file so a header the build sees is a header this checks -- # there is no hand-maintained list to fall out of date. # # Inputs (set by the including scope, or passed with -D in script mode): # PLOT_INCLUDE_DIR the installed-header root, e.g. /include # PLOT_UMBRELLA the umbrella header, e.g. /plot/plot.hpp if(NOT DEFINED PLOT_INCLUDE_DIR) message(FATAL_ERROR "plot: PLOT_INCLUDE_DIR is not set") endif() if(NOT DEFINED PLOT_UMBRELLA) set(PLOT_UMBRELLA "${PLOT_INCLUDE_DIR}/plot/plot.hpp") endif() file(GLOB_RECURSE plot_umbrella_headers RELATIVE "${PLOT_INCLUDE_DIR}" "${PLOT_INCLUDE_DIR}/plot/*.hpp") list(SORT plot_umbrella_headers) file(READ "${PLOT_UMBRELLA}" plot_umbrella_text) # The umbrella is a public header too, but it cannot include itself. file(RELATIVE_PATH plot_umbrella_relative "${PLOT_INCLUDE_DIR}" "${PLOT_UMBRELLA}") # Every other public header is named by the umbrella. set(plot_umbrella_missing "") foreach(header IN LISTS plot_umbrella_headers) if(header MATCHES "/detail/" OR header STREQUAL plot_umbrella_relative) continue() endif() string(FIND "${plot_umbrella_text}" "#include <${header}>" plot_umbrella_pos) if(plot_umbrella_pos EQUAL -1) list(APPEND plot_umbrella_missing "${header}") endif() endforeach() if(plot_umbrella_missing) string(REPLACE ";" "\n " plot_umbrella_missing_text "${plot_umbrella_missing}") message(FATAL_ERROR "plot: ${PLOT_UMBRELLA} does not include every public header under " "include/plot/ -- missing:\n ${plot_umbrella_missing_text}\n" "Add each as `#include `, or move it under a */detail/ directory " "if it is implementation-only and not part of the public surface.") endif() # And every header the umbrella names is a file that exists (a rename or a # deleted header cannot leave a dangling include behind). string(REGEX MATCHALL "#include ]+>" plot_umbrella_includes "${plot_umbrella_text}") set(plot_umbrella_dangling "") foreach(plot_umbrella_include IN LISTS plot_umbrella_includes) string(REGEX REPLACE "#include <([^>]+)>" "\\1" plot_umbrella_header "${plot_umbrella_include}") if(NOT EXISTS "${PLOT_INCLUDE_DIR}/${plot_umbrella_header}") list(APPEND plot_umbrella_dangling "${plot_umbrella_header}") endif() endforeach() if(plot_umbrella_dangling) string(REPLACE ";" "\n " plot_umbrella_dangling_text "${plot_umbrella_dangling}") message(FATAL_ERROR "plot: ${PLOT_UMBRELLA} includes headers that do not exist under " "include/plot/:\n ${plot_umbrella_dangling_text}") endif() list(LENGTH plot_umbrella_headers plot_umbrella_header_count) message(STATUS "plot: umbrella covers every public header (${plot_umbrella_header_count} headers globbed)")