Skip to content

build: decompose root CMakeLists.txt into cmake/*.cmake modules #1090

Description

@kcenon

What

Decompose the 1031-line root CMakeLists.txt by extracting inline directives into modular cmake/*.cmake files following the existing network_system_*.cmake naming convention.

Part of #1083.

Current state

  • Root CMakeLists.txt: 1031 lines.
  • cmake/ already has 5 modular files: network_system_dependencies.cmake, network_system_features.cmake, network_system_install.cmake, network_system_integration.cmake, network_system_cpack.cmake.
  • The remaining inline content includes ~24 option(...) declarations, compiler/standard setup, sanitizer wiring, ASIO recycling workaround, the main add_library(network_system ...) target rule (line 432), summary message(STATUS ...) block (lines 994-end).

Why

A 1031-line root file is the most bloated in the ecosystem (Master EPIC kcenon/common_system#657). Extraction recovers reviewability and makes future option additions a single-file diff instead of a search-and-insert into a wall of text.

Where

  • CMakeLists.txt (slim down to thin orchestrator)
  • cmake/ (new modules)

How

Technical approach

Extract inline directives into new modules using existing naming convention:

  • cmake/network_system_options.cmake — all option(...) declarations (~24)
  • cmake/network_system_compiler.cmake — C++ standard, CMAKE_POSITION_INDEPENDENT_CODE, compile-feature defaults
  • cmake/network_system_sanitizers.cmake — ASAN/TSAN/UBSAN flag wiring (mutually-exclusive enforcement)
  • cmake/network_system_targets.cmakenetwork_system library target rule + network-integration-objects + alias
  • cmake/network_system_summary.cmake — final message(STATUS ...) configuration printout

Root CMakeLists.txt becomes:

cmake_minimum_required(VERSION 3.20)
project(network_system VERSION 0.1.1 ...)
include(cmake/network_system_options.cmake)
include(cmake/network_system_compiler.cmake)
include(cmake/network_system_sanitizers.cmake)
include(cmake/network_system_dependencies.cmake)
include(cmake/network_system_targets.cmake)
include(cmake/network_system_features.cmake)
include(cmake/network_system_integration.cmake)
include(cmake/network_system_install.cmake)
include(cmake/network_system_cpack.cmake)
include(cmake/network_system_summary.cmake)
add_subdirectory(libs)
if(BUILD_TESTS) add_subdirectory(tests) endif()
# ... etc

Verification approach

For each extraction step:

  1. Diff the option list before vs after (no option silently dropped)
  2. Verify build matrix unchanged: default + -DBUILD_SAMPLES=ON -DBUILD_EXAMPLES=ON -DENABLE_ASAN=ON
  3. Verify install layout unchanged via cmake --install build/ --prefix /tmp/inst-after diff
  4. Verify downstream pacs_system build still succeeds (cross-build CI gate from Master EPIC)

Acceptance criteria

  • Root CMakeLists.txt ≤ 150 lines (orchestrator only)
  • All extracted modules follow network_system_*.cmake naming
  • Option list identical to pre-migration (verified by diff)
  • Build matrix unchanged on CI
  • Downstream pacs builds unchanged
  • CI green on PR

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions