fix(build): keep counter instrumentation out of the installed release library

The linux-release preset inherited PLOT_BUILD_TESTS=ON, so the release build
compiled the pyramid cover/merge and ring upload/wait/slot counters into
libplot_core.a and cmake --install shipped them. Set PLOT_BUILD_TESTS=OFF in the
preset; the suite keeps running in linux-debug and linux-asan, which are
unchanged.

Also pin the two header properties the plan calls Global Constraints and that
nothing guarded: every header under include/plot/ compiles standalone, and
include/plot/plot.hpp includes every public one. tests/CMakeLists.txt globs the
headers at configure time (CONFIGURE_DEPENDS) and generates one TU per header
plus an umbrella TU that constructs Plot, Renderer, data::StreamSeries and
input::Controller; a ctest entry builds the header TUs and runs the umbrella,
and cmake/plot_umbrella_check.cmake fails configure and ctest when a public
header is missing from the umbrella.
This commit is contained in:
Martino Ferrari committed 2026-09-28 03:25:59 +02:00
1 parent 0972903d27
commit f363523195
3 files changed
+149

No files matched your search

+2
View File
@@ -23,10 +23,12 @@
{
"name": "linux-release",
"displayName": "Linux Release",
"description": "Release artifact for install: PLOT_BUILD_TESTS is OFF so the installed libplot_core.a carries none of the test-only counter instrumentation (PLOT_PYRAMID_COUNT_*, PLOT_RING_STATS). The suite runs in linux-debug and linux-asan.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"PLOT_BUILD_TESTS": false,
"PLOT_BUILD_GLFW": true,
"PLOT_BUILD_IMGUI": true,
"PLOT_BUILD_EXAMPLES": true,
+76
View File
@@ -0,0 +1,76 @@
# 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 <plot/...> 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. <source>/include
# PLOT_UMBRELLA the umbrella header, e.g. <PLOT_INCLUDE_DIR>/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 <plot/...>`, 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/[^>]+>" 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)")
+71
View File
@@ -85,3 +85,74 @@ if(PLOT_ASAN_ENABLED)
set_tests_properties(plot_tests PROPERTIES ENVIRONMENT
"ASAN_OPTIONS=detect_leaks=1:print_suppressions=1:suppressions=${CMAKE_SOURCE_DIR}/cmake/plot_asan_suppressions.txt")
endif()
# --- public headers: standalone compilation and umbrella coverage -------------
#
# The plan's Global Constraints require every header under include/plot/ to
# compile standalone, and include/plot/plot.hpp to include every public one
# (never an adapter). Both were verified by hand and nothing kept them true, so
# a header added later could break either silently. These targets make the build
# enforce both and the ctest entries below make the suite fail when the checks
# do. The header list is globbed at configure time (CONFIGURE_DEPENDS, so adding
# or removing a header re-globs) -- a hand-kept list would defeat the point.
file(GLOB_RECURSE plot_public_headers CONFIGURE_DEPENDS
RELATIVE "${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/include/plot/*.hpp")
list(SORT plot_public_headers)
# One generated TU per header, each holding only that header's #include. An
# OBJECT library: this is a compile check, with no link step, so any header that
# needs something it does not itself include fails the build here.
set(plot_header_check_sources "")
foreach(plot_header IN LISTS plot_public_headers)
string(MAKE_C_IDENTIFIER "${plot_header}" plot_header_slug)
set(plot_header_check_source "${CMAKE_CURRENT_BINARY_DIR}/header_checks/${plot_header_slug}.cpp")
set(plot_header_check_content
"// Generated by tests/CMakeLists.txt: <${plot_header}> must compile on its own.\n#include <${plot_header}>\n")
file(GENERATE OUTPUT "${plot_header_check_source}" CONTENT "${plot_header_check_content}")
list(APPEND plot_header_check_sources "${plot_header_check_source}")
endforeach()
add_library(plot_header_self_containment OBJECT ${plot_header_check_sources})
target_link_libraries(plot_header_self_containment PRIVATE plot::core)
plot_apply_warnings(plot_header_self_containment)
# The umbrella on its own: the generated TU includes only <plot/plot.hpp> and
# constructs one of each layer's entry type, so an umbrella that misses a header
# -- or that is unusable without further includes -- fails to build. The test
# runs the linked binary, so a build that produced nothing usable still fails.
set(plot_umbrella_check_source "${CMAKE_CURRENT_BINARY_DIR}/umbrella_check.cpp")
file(GENERATE OUTPUT "${plot_umbrella_check_source}" CONTENT
"// Generated by tests/CMakeLists.txt: the umbrella must be usable by itself.
#include <plot/plot.hpp>
int main() {
plot::Plot plot;
plot::Renderer renderer;
plot::data::StreamSeries series(16, 0.0, 1.0);
plot::input::Controller controller(plot);
(void)renderer;
(void)series;
(void)controller;
return 0;
}
")
add_executable(plot_umbrella_check "${plot_umbrella_check_source}")
target_link_libraries(plot_umbrella_check PRIVATE plot::core)
plot_apply_warnings(plot_umbrella_check)
# Coverage check on the umbrella. Included here so a public header missing from
# plot.hpp stops the configure; the ctest entry below runs the same script again
# so the check is also a visible test.
set(PLOT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
set(PLOT_UMBRELLA "${CMAKE_SOURCE_DIR}/include/plot/plot.hpp")
include("${CMAKE_SOURCE_DIR}/cmake/plot_umbrella_check.cmake")
add_test(NAME plot_headers_self_contained
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --target plot_header_self_containment)
add_test(NAME plot_umbrella_covers_public_headers
COMMAND ${CMAKE_COMMAND}
-DPLOT_INCLUDE_DIR=${CMAKE_SOURCE_DIR}/include
-DPLOT_UMBRELLA=${CMAKE_SOURCE_DIR}/include/plot/plot.hpp
-P "${CMAKE_SOURCE_DIR}/cmake/plot_umbrella_check.cmake")
add_test(NAME plot_umbrella_check COMMAND plot_umbrella_check)