Skip to content

refactor(build): decompose root CMakeLists.txt into cmake/ modules#1096

Merged
kcenon merged 2 commits into
developfrom
refactor/issue-1090-decompose-cmakelists
May 2, 2026
Merged

refactor(build): decompose root CMakeLists.txt into cmake/ modules#1096
kcenon merged 2 commits into
developfrom
refactor/issue-1090-decompose-cmakelists

Conversation

@kcenon

@kcenon kcenon commented May 2, 2026

Copy link
Copy Markdown
Owner

Closes #1090

Summary

Extract inline directives from the 1019-line root CMakeLists.txt into purpose-specific
cmake/network_system_*.cmake modules. The root file becomes a 102-line thin
orchestrator that includes the modules in dependency order.

New modules

  • cmake/network_system_compiler.cmake (27 lines) — C++ standard, PIC, compile_commands
  • cmake/network_system_options.cmake (122 lines) — all option(...) declarations
  • cmake/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_system main library, TLS/WebSocket/LZ4/ZLIB/gRPC feature wiring, verify_build
  • cmake/network_system_subdirs.cmake (121 lines) — protocol library +
    tests/examples/benchmarks/fuzz add_subdirectory orchestration
  • cmake/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 printout

Existing 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:

  1. project() declaration
  2. compiler defaults / options / sanitizer wiring (function-definition modules also
    loaded, but they only register helpers — no targets/detection at include time)
  3. dependency + feature detection
  4. libs/network-core
  5. main library targets (network_system_targets.cmake)
  6. protocol libs + tests/examples/benchmarks/fuzz (network_system_subdirs.cmake)
  7. installation + CPack
  8. optional C++20 module target
  9. summary printout

This preserves the critical ordering invariants: function-definition includes precede
their first use, network-core is added before network_system so it can link against
it, network_system is created before any libs/network-* subdirectory tries to link
against network-integration-objects, and sanitizer flags are set before any
target_compile_features() runs.

Test Plan

  • All 22 user-visible options preserved (verified locally with sorted diff against
    the pre-extraction list — empty diff)
  • Build matrix unchanged: Debug/Release × Ubuntu/macOS — verified by CI
  • Option diff before/after — empty
  • Install layout — relies on CI verification
  • Downstream pacs builds — relies on CI verification

Local CMake configure was attempted but cmake is not installed in this sandbox; CI
covers Debug + Release + sanitizers + coverage on Ubuntu/macOS/Windows.

kcenon added 2 commits May 2, 2026 09:01
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
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Metric Value
Line Coverage 68.8%
Branch Coverage 34.2%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

@kcenon kcenon merged commit 9df87e9 into develop May 2, 2026
9 checks passed
@kcenon kcenon deleted the refactor/issue-1090-decompose-cmakelists branch May 2, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant