| name | build-optimization |
| description | Optimizes build times using Ninja, ccache, and Precompiled Headers (PCH). Use when adding new targets or heavy dependencies. |
Build Optimization & Performance
Core Principles
To maintain a fast development cycle, the build system is optimized for speed and efficiency. All modifications should respect these optimization patterns.
Optimization Tools
- ccache: Ensure
ccache is installed on your system. CMake is configured to automatically detect and use it to cache object files.
- Ninja: Use the Ninja build generator (
cmake -G Ninja) instead of Make for faster orchestration and better parallelism.
- Precompiled Headers (PCH):
- Heavy headers (STL, spdlog, nlohmann_json) are precompiled.
- Every new target should apply
${PROJECT_PCH_HEADERS} or ${TEST_PCH_HEADERS} using target_precompile_headers.
Build Directive
- Compile with Ninja: all builds should be executed using Ninja (i.e., a build directory configured with the Ninja generator). Do not use Make-based builds.
Build Configurations
- Unity Builds: Grouping multiple source files to reduce preprocessor load. Toggle with
-DENABLE_UNITY_BUILD=ON/OFF.
- Incremental Builds: Optimization of PCH and ccache usage to keep incremental build times minimal.
Best Practices
Workflow Integration
- Understand: Assess the impact of new code on build times and runtime performance.
- Plan: Choose appropriate header inclusion methods (forward declarations vs. includes) and ensure new targets use PCH.
- Implement: Apply build optimization best practices when creating or modifying targets.
- Verify (Tests): Monitor compilation times and run benchmarks if performance-critical code is changed.
- Verify (Standards): Verify that all new build targets are correctly configured for PCH and follow unity build compatibility rules.