Skip to content

Commit 99d884e

Browse files
committed
refactor(cmake): replace hardcoded source lists with structured globbing
Replace every remaining hardcoded .cpp/.h listing in the build with file(GLOB ... CONFIGURE_DEPENDS) so CMake auto-detects new sources on reconfigure, eliminating drift between filesystem and build lists. Hardcoded blocks replaced (8): - CMakeLists.txt MONITORING_MODULE_SOURCES (4 .cppm paths) - CMakeLists.txt monitoring_hardware_plugin sources (5 .cpp paths) - CMakeLists.txt monitoring_container_plugin sources (1 .cpp path) - CMakeLists.txt install(FILES adapters/*.h) (9 .h paths) - tests/CMakeLists.txt monitoring_system_tests (~46 .cpp paths) - examples/CMakeLists.txt 17 single-file add_executable blocks - benchmarks/CMakeLists.txt monitoring_benchmarks (6 .cpp paths) - integration_tests/CMakeLists.txt SCENARIO/PERFORMANCE/FAILURE_TESTS GLOBs that gained CONFIGURE_DEPENDS (5): - MONITORING_HEADERS, MONITORING_SOURCES (main library) - SCENARIO_TESTS, PERFORMANCE_TESTS, FAILURE_TESTS (integration tests) Hardware/container plugin libraries no longer redundantly recompile collector .cpp files that the main monitoring_system library already provides via its MONITORING_SOURCES glob and PUBLIC dependency. The plugin libraries now compile only their own wrappers; collector code is linked transitively. Tests intentionally excluded from monitoring_system_tests are kept out via list(REMOVE_ITEM): test_buffering_strategies (depends on internal headers), test_collector_registry (superseded), and test_thread_context (superseded by test_thread_context_simple). Examples that are not currently buildable (PoCs, work-in-progress TODOs, depend on internal APIs) are similarly excluded by name from the example glob to preserve prior behaviour. Closes #677 Part of #674
1 parent 94d1f17 commit 99d884e

5 files changed

Lines changed: 110 additions & 304 deletions

File tree

CMakeLists.txt

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,13 @@ set(MONITORING_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
519519
set(MONITORING_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
520520

521521
# Collect source files
522-
file(GLOB_RECURSE MONITORING_HEADERS
522+
# CONFIGURE_DEPENDS makes CMake re-run the glob check at build time, so newly
523+
# added/removed files are picked up without manually re-running cmake.
524+
file(GLOB_RECURSE MONITORING_HEADERS CONFIGURE_DEPENDS
523525
${MONITORING_INCLUDE_DIR}/kcenon/monitoring/*.h
524526
)
525527

526-
file(GLOB_RECURSE MONITORING_SOURCES
528+
file(GLOB_RECURSE MONITORING_SOURCES CONFIGURE_DEPENDS
527529
${MONITORING_SOURCE_DIR}/*.cpp
528530
)
529531

@@ -558,12 +560,10 @@ target_link_libraries(monitoring_system PUBLIC
558560
# kcenon.monitoring.adaptive - Adaptive monitoring
559561
##################################################
560562
if(MONITORING_ENABLE_MODULES)
561-
# Define module source files
562-
set(MONITORING_MODULE_SOURCES
563-
${CMAKE_CURRENT_SOURCE_DIR}/src/modules/monitoring.cppm
564-
${CMAKE_CURRENT_SOURCE_DIR}/src/modules/core.cppm
565-
${CMAKE_CURRENT_SOURCE_DIR}/src/modules/collectors.cppm
566-
${CMAKE_CURRENT_SOURCE_DIR}/src/modules/adaptive.cppm
563+
# Collect module source files
564+
# CONFIGURE_DEPENDS picks up new .cppm files on reconfigure without manual list edits.
565+
file(GLOB_RECURSE MONITORING_MODULE_SOURCES CONFIGURE_DEPENDS
566+
${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*.cppm
567567
)
568568

569569
# Create module library
@@ -719,12 +719,17 @@ endif()
719719
if(MONITORING_BUILD_HARDWARE_PLUGIN)
720720
message(STATUS "=== Building Hardware Monitoring Plugin ===")
721721

722+
# Hardware plugin sources (plugin wrapper only).
723+
# Collector implementations (battery, power, temperature, gpu) are already
724+
# compiled into monitoring_system (the main library) via the MONITORING_SOURCES
725+
# GLOB; they are linked transitively through the PUBLIC dependency declared
726+
# below, so the plugin library only needs to compile the plugin wrapper itself.
727+
file(GLOB_RECURSE MONITORING_HARDWARE_PLUGIN_SOURCES CONFIGURE_DEPENDS
728+
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/hardware/*.cpp
729+
)
730+
722731
add_library(monitoring_hardware_plugin STATIC
723-
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/hardware/hardware_plugin.cpp
724-
${CMAKE_CURRENT_SOURCE_DIR}/src/collectors/battery_collector.cpp
725-
${CMAKE_CURRENT_SOURCE_DIR}/src/platform/power_collector.cpp
726-
${CMAKE_CURRENT_SOURCE_DIR}/src/platform/temperature_collector.cpp
727-
${CMAKE_CURRENT_SOURCE_DIR}/src/platform/gpu_collector.cpp
732+
${MONITORING_HARDWARE_PLUGIN_SOURCES}
728733
)
729734

730735
target_include_directories(monitoring_hardware_plugin
@@ -768,8 +773,15 @@ endif()
768773
if(MONITORING_BUILD_CONTAINER_PLUGIN)
769774
message(STATUS "=== Building Container Monitoring Plugin ===")
770775

776+
# Container plugin sources (plugin wrapper). Underlying collector
777+
# implementations are compiled into monitoring_system via MONITORING_SOURCES
778+
# and linked transitively through the PUBLIC dependency below.
779+
file(GLOB_RECURSE MONITORING_CONTAINER_PLUGIN_SOURCES CONFIGURE_DEPENDS
780+
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/container/*.cpp
781+
)
782+
771783
add_library(monitoring_container_plugin STATIC
772-
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/container/container_plugin.cpp
784+
${MONITORING_CONTAINER_PLUGIN_SOURCES}
773785
)
774786

775787
target_include_directories(monitoring_container_plugin
@@ -833,16 +845,14 @@ install(DIRECTORY include/kcenon/monitoring
833845
FILES_MATCHING PATTERN "*.h"
834846
)
835847

848+
# Adapter headers are also collected via the install(DIRECTORY ...) call above,
849+
# but this explicit install is retained for the COMPONENT Development tag.
850+
file(GLOB MONITORING_ADAPTER_HEADERS CONFIGURE_DEPENDS
851+
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/*.h
852+
)
853+
836854
install(FILES
837-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/common_adapters.h
838-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/thread_adapters.h
839-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/logger_adapters.h
840-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/common_to_monitoring_adapter.h
841-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/monitoring_to_common_adapter.h
842-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/thread_to_monitoring_adapter.h
843-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/logger_to_monitoring_adapter.h
844-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/monitor_adapter.h
845-
${CMAKE_CURRENT_SOURCE_DIR}/include/kcenon/monitoring/adapters/performance_monitor_adapter.h
855+
${MONITORING_ADAPTER_HEADERS}
846856
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kcenon/monitoring/adapters
847857
COMPONENT Development
848858
)

benchmarks/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ endif()
1717
if(benchmark_FOUND OR BENCHMARK_FOUND)
1818
message(STATUS "Google Benchmark found. Building monitoring_system benchmarks...")
1919

20+
# Collect benchmark sources via glob.
21+
# CONFIGURE_DEPENDS picks up newly-added benchmark files on reconfigure.
22+
file(GLOB MONITORING_BENCHMARK_SOURCES CONFIGURE_DEPENDS
23+
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
24+
)
25+
2026
# Benchmark executable
2127
add_executable(monitoring_benchmarks
22-
core_metrics_bench.cpp
23-
metric_collection_bench.cpp
24-
event_bus_bench.cpp
25-
collector_overhead_bench.cpp
26-
adaptive_monitor_bench.cpp
27-
main_bench.cpp
28+
${MONITORING_BENCHMARK_SOURCES}
2829
)
2930

3031
target_link_libraries(monitoring_benchmarks

examples/CMakeLists.txt

Lines changed: 41 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -6,162 +6,51 @@ include_directories(
66
${CMAKE_SOURCE_DIR}/include
77
)
88

9-
# Basic monitoring example
10-
add_executable(basic_monitoring_example
11-
basic_monitoring_example.cpp
12-
)
13-
target_link_libraries(basic_monitoring_example
14-
PRIVATE monitoring_system
15-
Threads::Threads
16-
)
17-
18-
# Distributed tracing example
19-
add_executable(distributed_tracing_example
20-
distributed_tracing_example.cpp
21-
)
22-
target_link_libraries(distributed_tracing_example
23-
PRIVATE monitoring_system
24-
Threads::Threads
25-
)
26-
27-
# Health monitoring and reliability example
28-
add_executable(health_reliability_example
29-
health_reliability_example.cpp
30-
)
31-
target_link_libraries(health_reliability_example
32-
PRIVATE monitoring_system
33-
Threads::Threads
34-
)
35-
36-
# Result pattern example (existing)
37-
add_executable(result_pattern_example
38-
result_pattern_example.cpp
39-
)
40-
target_link_libraries(result_pattern_example
41-
PRIVATE monitoring_system
42-
Threads::Threads
43-
)
44-
45-
# Custom metric types example (histogram, summary, timer)
46-
add_executable(custom_metric_types_example
47-
custom_metric_types_example.cpp
48-
)
49-
target_link_libraries(custom_metric_types_example
50-
PRIVATE monitoring_system
51-
Threads::Threads
52-
)
53-
54-
# Alert system examples
55-
add_executable(alert_pipeline_example
56-
alert_pipeline_example.cpp
57-
)
58-
target_link_libraries(alert_pipeline_example
59-
PRIVATE monitoring_system
60-
Threads::Threads
61-
)
62-
63-
add_executable(alert_triggers_example
64-
alert_triggers_example.cpp
65-
)
66-
target_link_libraries(alert_triggers_example
67-
PRIVATE monitoring_system
68-
Threads::Threads
69-
)
70-
71-
add_executable(alert_notifiers_example
72-
alert_notifiers_example.cpp
73-
)
74-
target_link_libraries(alert_notifiers_example
75-
PRIVATE monitoring_system
76-
Threads::Threads
77-
)
78-
79-
# Phase 2: Unified Collector Examples
80-
add_executable(system_collectors_example
81-
system_collectors_example.cpp
82-
)
83-
target_link_libraries(system_collectors_example
84-
PRIVATE monitoring_system
85-
Threads::Threads
86-
)
87-
88-
add_executable(platform_metrics_example
89-
platform_metrics_example.cpp
90-
)
91-
target_link_libraries(platform_metrics_example
92-
PRIVATE monitoring_system
93-
Threads::Threads
94-
)
95-
96-
add_executable(collector_factory_example
97-
collector_factory_example.cpp
98-
)
99-
target_link_libraries(collector_factory_example
100-
PRIVATE monitoring_system
101-
Threads::Threads
102-
)
103-
104-
# Phase 3: Advanced Integration Examples
105-
add_executable(otlp_export_example
106-
otlp_export_example.cpp
107-
)
108-
target_link_libraries(otlp_export_example
109-
PRIVATE monitoring_system
110-
Threads::Threads
111-
)
112-
113-
add_executable(time_series_storage_example
114-
time_series_storage_example.cpp
115-
)
116-
target_link_libraries(time_series_storage_example
117-
PRIVATE monitoring_system
118-
Threads::Threads
119-
)
120-
121-
add_executable(multi_service_tracing_example
122-
multi_service_tracing_example.cpp
123-
)
124-
target_link_libraries(multi_service_tracing_example
125-
PRIVATE monitoring_system
126-
Threads::Threads
127-
)
128-
129-
# Phase 4: Production Patterns Examples
130-
add_executable(production_monitoring_example
131-
production_monitoring_example.cpp
132-
)
133-
target_link_libraries(production_monitoring_example
134-
PRIVATE monitoring_system
135-
Threads::Threads
136-
)
137-
138-
add_executable(graceful_degradation_example
139-
graceful_degradation_example.cpp
140-
)
141-
target_link_libraries(graceful_degradation_example
142-
PRIVATE monitoring_system
143-
Threads::Threads
144-
)
145-
146-
# Phase 4 DI Pattern examples - available when common_system integration is enabled
147-
if(MONITORING_WITH_COMMON_SYSTEM OR MONITORING_USING_COMMON_INTERFACES)
148-
# Logger DI Integration example
149-
add_executable(logger_di_integration_example
150-
logger_di_integration_example.cpp
151-
)
152-
target_link_libraries(logger_di_integration_example
9+
# Collect example sources via glob; each example is a single-file executable.
10+
# CONFIGURE_DEPENDS picks up newly-added examples on reconfigure.
11+
file(GLOB MONITORING_EXAMPLE_SOURCES CONFIGURE_DEPENDS
12+
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
13+
)
14+
15+
# Examples that are not currently built. Reasons vary (depend on internal
16+
# headers, proof-of-concept code, type mismatches awaiting fix). Keeping the
17+
# files in-tree but skipping their target registration mirrors the prior
18+
# behaviour after this glob conversion.
19+
list(REMOVE_ITEM MONITORING_EXAMPLE_SOURCES
20+
${CMAKE_CURRENT_SOURCE_DIR}/bidirectional_di_example.cpp
21+
${CMAKE_CURRENT_SOURCE_DIR}/event_bus_example.cpp
22+
${CMAKE_CURRENT_SOURCE_DIR}/facade_adapter_poc.cpp
23+
${CMAKE_CURRENT_SOURCE_DIR}/monitor_factory_pattern_example.cpp
24+
${CMAKE_CURRENT_SOURCE_DIR}/plugin_collector_example.cpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/storage_example.cpp
26+
)
27+
28+
# Examples gated on common_system integration. Removed from the unconditional
29+
# list; re-added below inside the if() block.
30+
set(MONITORING_COMMON_SYSTEM_EXAMPLES
31+
${CMAKE_CURRENT_SOURCE_DIR}/logger_di_integration_example.cpp
32+
)
33+
list(REMOVE_ITEM MONITORING_EXAMPLE_SOURCES ${MONITORING_COMMON_SYSTEM_EXAMPLES})
34+
35+
foreach(_example_src IN LISTS MONITORING_EXAMPLE_SOURCES)
36+
get_filename_component(_example_name "${_example_src}" NAME_WE)
37+
add_executable(${_example_name} ${_example_src})
38+
target_link_libraries(${_example_name}
15339
PRIVATE monitoring_system
15440
Threads::Threads
15541
)
42+
endforeach()
15643

157-
# Monitor Factory Pattern example (TODO: Fix type mismatches)
158-
# add_executable(monitor_factory_pattern_example
159-
# monitor_factory_pattern_example.cpp
160-
# )
161-
# target_link_libraries(monitor_factory_pattern_example
162-
# PRIVATE monitoring_system
163-
# Threads::Threads
164-
# )
44+
# Phase 4 DI Pattern examples - available when common_system integration is enabled
45+
if(MONITORING_WITH_COMMON_SYSTEM OR MONITORING_USING_COMMON_INTERFACES)
46+
foreach(_example_src IN LISTS MONITORING_COMMON_SYSTEM_EXAMPLES)
47+
get_filename_component(_example_name "${_example_src}" NAME_WE)
48+
add_executable(${_example_name} ${_example_src})
49+
target_link_libraries(${_example_name}
50+
PRIVATE monitoring_system
51+
Threads::Threads
52+
)
53+
endforeach()
16554

16655
message(STATUS "Phase 4 DI pattern examples enabled for monitoring_system")
16756
endif()

integration_tests/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ include_directories(
4040
${CMAKE_SOURCE_DIR}/sources
4141
)
4242

43-
# Collect all test source files
44-
file(GLOB SCENARIO_TESTS scenarios/*.cpp)
45-
file(GLOB PERFORMANCE_TESTS performance/*.cpp)
46-
file(GLOB FAILURE_TESTS failures/*.cpp)
43+
# Collect all test source files.
44+
# CONFIGURE_DEPENDS makes CMake re-run the glob on build when files are added/removed.
45+
file(GLOB SCENARIO_TESTS CONFIGURE_DEPENDS scenarios/*.cpp)
46+
file(GLOB PERFORMANCE_TESTS CONFIGURE_DEPENDS performance/*.cpp)
47+
file(GLOB FAILURE_TESTS CONFIGURE_DEPENDS failures/*.cpp)
4748

4849
# Create integration test executable
4950
add_executable(monitoring_integration_tests

0 commit comments

Comments
 (0)