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/DemoConfig.cmake | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 cmake/DemoConfig.cmake (limited to 'cmake/DemoConfig.cmake') diff --git a/cmake/DemoConfig.cmake b/cmake/DemoConfig.cmake new file mode 100644 index 0000000..b3167c4 --- /dev/null +++ b/cmake/DemoConfig.cmake @@ -0,0 +1,77 @@ +# Configuration Implications and Platform Detection +# Processes build options and sets up platform-specific definitions + +# Option hierarchy: ALL_OPTIONS → FINAL_STRIP → STRIP_ALL → SIZE_OPT +if(DEMO_ALL_OPTIONS) + set(DEMO_SIZE_OPT ON) + set(DEMO_STRIP_ALL ON) + set(DEMO_BUILD_TESTS ON) + set(DEMO_BUILD_TOOLS ON) + # NOTE: DEMO_FINAL_STRIP is NOT included here (too dangerous for testing) +endif() + +# FINAL_STRIP: Most aggressive stripping (removes ALL error checking) +# Implies STRIP_ALL (stricter superset) +if(DEMO_FINAL_STRIP) + add_definitions(-DFINAL_STRIP) + set(DEMO_STRIP_ALL ON) + message(STATUS "FINAL_STRIP enabled - all error checking will be removed") +endif() + +if(DEMO_STRIP_ALL) + add_definitions(-DSTRIP_ALL) + set(DEMO_SIZE_OPT ON) +endif() + +if(DEMO_STRIP_EXTERNAL_LIBS) + add_definitions(-DSTRIP_EXTERNAL_LIBS) + # Audio: Use miniaudio null backend + add_definitions(-DMA_ENABLE_ONLY_SPECIFIC_BACKENDS -DMA_ENABLE_NULL) + message(STATUS "STRIP_EXTERNAL_LIBS enabled - binary will compile but NOT run (size measurement only)") +endif() + +if(DEMO_ENABLE_COVERAGE AND APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + # Coverage requires debug info + set(CMAKE_BUILD_TYPE Debug) +endif() + +if(DEMO_ENABLE_DEBUG_LOGS) + add_definitions(-DDEBUG_LOG_ALL) +endif() + +if(DEMO_HEADLESS) + add_definitions(-DDEMO_HEADLESS) + add_definitions(-DMA_ENABLE_ONLY_SPECIFIC_BACKENDS -DMA_ENABLE_NULL) + message(STATUS "DEMO_HEADLESS enabled - functional stubs (audio works, no GPU)") +endif() + +# Platform-specific definitions +if(APPLE) + add_definitions(-DGLFW_EXPOSE_NATIVE_COCOA) +elseif(WIN32) + add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32) +elseif(UNIX) + if(DEFINED CMAKE_USE_WAYLAND) + add_definitions(-DGLFW_EXPOSE_NATIVE_WAYLAND) + else() + add_definitions(-DGLFW_EXPOSE_NATIVE_X11) + endif() +endif() + +# Configuration summary +message(STATUS "") +message(STATUS "Build Configuration:") +message(STATUS " DEMO_SIZE_OPT: ${DEMO_SIZE_OPT}") +message(STATUS " DEMO_STRIP_ALL: ${DEMO_STRIP_ALL}") +message(STATUS " DEMO_FINAL_STRIP: ${DEMO_FINAL_STRIP}") +message(STATUS " DEMO_STRIP_EXTERNAL_LIBS: ${DEMO_STRIP_EXTERNAL_LIBS}") +message(STATUS " DEMO_BUILD_TESTS: ${DEMO_BUILD_TESTS}") +message(STATUS " DEMO_BUILD_TOOLS: ${DEMO_BUILD_TOOLS}") +message(STATUS " DEMO_ENABLE_COVERAGE: ${DEMO_ENABLE_COVERAGE}") +message(STATUS " DEMO_ENABLE_DEBUG_LOGS: ${DEMO_ENABLE_DEBUG_LOGS}") +message(STATUS " DEMO_HEADLESS: ${DEMO_HEADLESS}") +message(STATUS " DEMO_WORKSPACE: ${DEMO_WORKSPACE}") +message(STATUS "") -- cgit v1.2.3