From fdf9345d5de1c951603e5da3ee8454e9efe2dc28 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 11 Feb 2026 08:19:05 +0100 Subject: refactor: Modularize CMake build system into 10 specialized modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor monolithic 866-line CMakeLists.txt into 54-line orchestrator + 10 modules: - DemoOptions.cmake - Build option declarations - DemoConfig.cmake - Option implications and platform detection - DemoCommon.cmake - Shared macros (conditional sources, size opts, linking) - DemoDependencies.cmake - External library discovery (WGPU, GLFW) - DemoSourceLists.cmake - Conditional source file lists - DemoLibraries.cmake - Subsystem library targets - DemoTools.cmake - Build tools (asset_packer, compilers) - DemoCodegen.cmake - Code generation (assets, timeline, music) - DemoExecutables.cmake - Main binaries (demo64k, test_demo) - DemoTests.cmake - Test infrastructure (36 tests) - Validation.cmake - Uniform buffer validation Benefits: - 94% reduction in main file size (866 → 54 lines) - Conditional module inclusion (tests only parsed if DEMO_BUILD_TESTS=ON) - Shared macros eliminate 200+ lines of repetition - Clear separation of concerns All 36 tests passing. All build modes verified. Documentation: Created doc/CMAKE_MODULES.md with module architecture. Co-Authored-By: Claude Sonnet 4.5 --- cmake/DemoTools.cmake | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cmake/DemoTools.cmake (limited to 'cmake/DemoTools.cmake') diff --git a/cmake/DemoTools.cmake b/cmake/DemoTools.cmake new file mode 100644 index 0000000..8c589f1 --- /dev/null +++ b/cmake/DemoTools.cmake @@ -0,0 +1,48 @@ +# Build Tools Setup +# Configures asset_packer, seq_compiler, and tracker_compiler + +# Asset packer tool +if(DEFINED ASSET_PACKER_PATH) + set(ASSET_PACKER_CMD ${ASSET_PACKER_PATH}) + set(ASSET_PACKER_DEPENDS ${ASSET_PACKER_PATH}) +else() + add_executable(asset_packer tools/asset_packer.cc) + target_link_libraries(asset_packer PRIVATE procedural) + target_include_directories(asset_packer PRIVATE third_party) + set(ASSET_PACKER_CMD $) + set(ASSET_PACKER_DEPENDS asset_packer) +endif() + +# Sequence compiler tool +if(DEFINED SEQ_COMPILER_PATH) + set(SEQ_COMPILER_CMD ${SEQ_COMPILER_PATH}) + set(SEQ_COMPILER_DEPENDS ${SEQ_COMPILER_PATH}) +else() + add_executable(seq_compiler tools/seq_compiler.cc) + set(SEQ_COMPILER_CMD $) + set(SEQ_COMPILER_DEPENDS seq_compiler) +endif() + +# Tracker compiler tool +if(DEFINED TRACKER_COMPILER_PATH) + set(TRACKER_COMPILER_CMD ${TRACKER_COMPILER_PATH}) + set(TRACKER_COMPILER_DEPENDS ${TRACKER_COMPILER_PATH}) +else() + add_executable(tracker_compiler tools/tracker_compiler.cc) + set(TRACKER_COMPILER_CMD $) + set(TRACKER_COMPILER_DEPENDS tracker_compiler) +endif() + +# Always build a host-native tracker_compiler for code generation purposes +add_executable(tracker_compiler_host tools/tracker_compiler.cc) +set_target_properties(tracker_compiler_host PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tools_host") + +# Determine which tracker compiler to use for code generation +if(DEMO_CROSS_COMPILE_WIN32) + set(TRACKER_COMPILER_FINAL_CMD "${CMAKE_SOURCE_DIR}/build_native/tools_host/tracker_compiler_host") + set(TRACKER_COMPILER_FINAL_DEPENDS tracker_compiler_host) +else() + set(TRACKER_COMPILER_FINAL_CMD ${TRACKER_COMPILER_CMD}) + set(TRACKER_COMPILER_FINAL_DEPENDS ${TRACKER_COMPILER_DEPENDS}) +endif() -- cgit v1.2.3