refactor(build): decompose root CMakeLists.txt into cmake/ modules#1096
Merged
Conversation
The root CMakeLists.txt has accumulated 1019 lines of inline build
directives mixed with orchestration. Extract everything substantive
into purpose-specific modules under cmake/ following the existing
network_system_*.cmake naming convention.
New modules:
- network_system_compiler.cmake: C++ standard, PIC, compile_commands
- network_system_options.cmake: all option(...) declarations
- network_system_sanitizers.cmake: ASAN/TSAN/UBSAN/coverage wiring,
ASIO recycling workaround, test environment helpers
- network_system_targets.cmake: network-integration-objects + main
network_system library + verify_build (TLS/WebSocket/LZ4/ZLIB/
gRPC feature wiring lives here next to its target)
- network_system_subdirs.cmake: protocol libs + tests/examples/
benchmarks/fuzz add_subdirectory orchestration
- network_system_modules.cmake: optional C++20 module library
(gated on NETWORK_BUILD_MODULES, no-op when off)
- network_system_summary.cmake: final configuration printout
Behavior preservation:
- All 22 user-visible options are kept verbatim
(verified by sorted diff against the pre-extraction list)
- Module include order matches the previous inline order so
function-definition includes still precede their first use,
network-core is added before network_system, network_system
is created before libs/network-tcp tries to link against
network-integration-objects, and sanitizer flags are set before
any target_compile_features() runs
- Existing helper modules (network_system_dependencies.cmake,
_features, _integration, _install, _cpack) are unchanged
Root CMakeLists.txt now: 102 lines (was 1019), reading top-to-bottom
as a phase-by-phase orchestrator. Adding a new option, sanitizer, or
install rule should now be a single-file diff against the matching
module.
Closes #1090
…in target CI on PR #1096 (macOS Debug) failed with: src/internal/tcp/tcp_socket.h:19:10: fatal error: 'kcenon/network-core/interfaces/socket_observer.h' file not found Root cause: in develop the modular protocol libraries (libs/network-tcp / libs/network-udp) are add_subdirectory()'d BEFORE the main network_system library is created, so when network_system links PUBLIC against network-tcp it inherits the root-level network-core/include path that network-tcp exposes via target_include_directories(... PUBLIC ...). The first iteration of the decomposition collapsed the entire build into network_system_targets.cmake and put libs/network-* add_subdirectory() calls AFTER add_library(network_system), so the if(TARGET network-tcp) link was a silent no-op and network_system lost the root-level network-core/include path. Fix: - Extract the network-integration-objects OBJECT library (and its internal symlink + ASIO/common_system wiring) into cmake/network_system_integration_objects.cmake. - Extract the protocol libs add_subdirectory() block into cmake/network_system_protocol_libs.cmake. - Trim cmake/network_system_targets.cmake to the main network_system library (and verify_build). - Reorder root CMakeLists.txt to: libs/network-core network_system_integration_objects.cmake network_system_protocol_libs.cmake network_system_targets.cmake network_system_subdirs.cmake (tests/examples/etc.) which mirrors develop's pre-refactor inline order. Behavior: 22-option set still preserved (verified with sorted diff against the pre-extraction list, exit 0). Refs #1090
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
This was referenced May 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1090
Summary
Extract inline directives from the 1019-line root CMakeLists.txt into purpose-specific
cmake/network_system_*.cmakemodules. The root file becomes a 102-line thinorchestrator that includes the modules in dependency order.
New modules
cmake/network_system_compiler.cmake(27 lines) — C++ standard, PIC, compile_commandscmake/network_system_options.cmake(122 lines) — alloption(...)declarationscmake/network_system_sanitizers.cmake(168 lines) — ASAN/TSAN/UBSAN/coverage wiring,ASIO recycling workaround, test-environment helpers (
network_gtest_discover_tests,network_apply_test_environment)cmake/network_system_targets.cmake(519 lines) —network-integration-objects,network_systemmain library, TLS/WebSocket/LZ4/ZLIB/gRPC feature wiring,verify_buildcmake/network_system_subdirs.cmake(121 lines) — protocol library +tests/examples/benchmarks/fuzz
add_subdirectoryorchestrationcmake/network_system_modules.cmake(88 lines) — optional C++20 module library(gated on
NETWORK_BUILD_MODULES, no-op when off)cmake/network_system_summary.cmake(46 lines) — final configuration printoutExisting modules preserved unchanged
network_system_dependencies.cmake,network_system_features.cmake,network_system_integration.cmake,network_system_install.cmake,network_system_cpack.cmake.What
Root CMakeLists.txt: 1019 lines → 102 lines (orchestrator only).
Why
A 1019-line root file is the most bloated build script in the ecosystem (Master EPIC
kcenon/common_system#657). Adding a new option used to require search-and-insert into a
wall of text; with this layout it becomes a single-file diff against the matching module.
How
Module include order matches the previous inline order:
project()declarationloaded, but they only register helpers — no targets/detection at include time)
libs/network-corenetwork_system_targets.cmake)network_system_subdirs.cmake)This preserves the critical ordering invariants: function-definition includes precede
their first use,
network-coreis added beforenetwork_systemso it can link againstit,
network_systemis created before anylibs/network-*subdirectory tries to linkagainst
network-integration-objects, and sanitizer flags are set before anytarget_compile_features()runs.Test Plan
the pre-extraction list — empty diff)
pacsbuilds — relies on CI verificationLocal CMake configure was attempted but
cmakeis not installed in this sandbox; CIcovers Debug + Release + sanitizers + coverage on Ubuntu/macOS/Windows.