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/DemoDependencies.cmake | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cmake/DemoDependencies.cmake (limited to 'cmake/DemoDependencies.cmake') diff --git a/cmake/DemoDependencies.cmake b/cmake/DemoDependencies.cmake new file mode 100644 index 0000000..daac571 --- /dev/null +++ b/cmake/DemoDependencies.cmake @@ -0,0 +1,33 @@ +# External Dependencies and Includes +# Finds and configures external libraries (WGPU, GLFW, platform libs) + +set(CORE_INCLUDES src third_party) + +if(DEMO_CROSS_COMPILE_WIN32) + add_definitions(-DDEMO_CROSS_COMPILE_WIN32) + set(WINDOWS_DEPS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/windows") + set(WGPU_INCLUDE_DIR "${WINDOWS_DEPS_DIR}/include") + set(WGPU_LIBRARY "${WINDOWS_DEPS_DIR}/lib/libwgpu_native.dll.a") + set(GLFW3_INCLUDE_DIR "${WINDOWS_DEPS_DIR}/include") + set(GLFW3_LIBRARY "${WINDOWS_DEPS_DIR}/lib/libglfw3.a") + + list(APPEND CORE_INCLUDES ${WGPU_INCLUDE_DIR} ${WGPU_INCLUDE_DIR}/webgpu ${GLFW3_INCLUDE_DIR}) + set(DEMO_LIBS ${GLFW3_LIBRARY} ${WGPU_LIBRARY} -lgdi32 -lws2_32 -luser32 -lkernel32 -lshell32 -ladvapi32 -ldwmapi) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") +else() + find_library(WGPU_LIBRARY NAMES wgpu_native libwgpu_native REQUIRED) + find_path(WGPU_ROOT_INCLUDE_DIR NAMES wgpu.h REQUIRED) + list(APPEND CORE_INCLUDES ${WGPU_ROOT_INCLUDE_DIR} ${WGPU_ROOT_INCLUDE_DIR}/webgpu-headers) + find_package(glfw3 REQUIRED) + set(DEMO_LIBS glfw ${WGPU_LIBRARY}) +endif() + +list(APPEND CORE_INCLUDES third_party/glfw3webgpu) +include_directories(${CORE_INCLUDES}) + +if(APPLE) + set_source_files_properties(src/platform/platform.cc third_party/glfw3webgpu/glfw3webgpu.c PROPERTIES COMPILE_FLAGS "-x objective-c++") + list(APPEND DEMO_LIBS "-framework Metal" "-framework Foundation" "-framework Cocoa" "-framework QuartzCore") +elseif(NOT DEMO_CROSS_COMPILE_WIN32) + list(APPEND DEMO_LIBS pthread m dl) +endif() -- cgit v1.2.3