cpp-large-scale
Patterns and toolchain guidance for large-scale C++ projects — CMake Presets, dependency management, build acceleration, static analysis pipelines, physical design, and codebase navigation.
What this skill does
# Large-Scale C++ Project Patterns
Domain knowledge for managing C++ codebases with 100K+ lines, multiple libraries, and team-scale development.
## When to Activate
- Setting up or restructuring a large C++ project
- Configuring CMake for multi-config, multi-platform builds
- Integrating package managers (vcpkg, Conan)
- Optimizing build times (ccache, precompiled headers, unity builds)
- Setting up static analysis pipelines (clang-tidy, cppcheck, iwyu)
- Designing module boundaries and physical layout
## CMake Presets
Use `CMakePresets.json` for reproducible, shareable build configurations:
```json
{
"version": 6,
"cmakeMinimumRequired": { "major": 3, "minor": 25, "patch": 0 },
"configurePresets": [
{
"name": "default",
"hidden": true,
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"BUILD_TESTING": "ON"
}
},
{
"name": "debug",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "-g -O0 -fno-omit-frame-pointer"
}
},
{
"name": "release",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS": "-O3 -march=native -DNDEBUG"
}
},
{
"name": "relwithdebinfo",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_CXX_FLAGS": "-O2 -g -DNDEBUG"
}
},
{
"name": "sanitize",
"inherits": "debug",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-g -O1 -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all"
}
},
{
"name": "coverage",
"inherits": "debug",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
}
}
],
"buildPresets": [
{ "name": "debug", "configurePreset": "debug" },
{ "name": "release", "configurePreset": "release", "jobs": 0 },
{ "name": "sanitize", "configurePreset": "sanitize" }
],
"testPresets": [
{
"name": "debug",
"configurePreset": "debug",
"output": { "outputOnFailure": true }
}
]
}
```
Usage:
```bash
cmake --preset debug # Configure
cmake --build --preset debug # Build
ctest --preset debug # Test
```
## Build Acceleration
### ccache / sccache
```bash
# Install
sudo apt install ccache # or: cargo install sccache
# CMake integration (add to preset or CLI)
cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
# Verify hit rate
ccache -s
```
### Precompiled Headers (PCH)
```cmake
# CMakeLists.txt — heavy STL/third-party headers
target_precompile_headers(mylib PRIVATE
<vector>
<string>
<unordered_map>
<memory>
<algorithm>
<fmt/format.h>
<spdlog/spdlog.h>
)
# Reuse PCH across targets
target_precompile_headers(myapp REUSE_FROM mylib)
```
### Unity Builds (Jumbo Compilation)
```cmake
# Merge translation units to reduce redundant header parsing
set(CMAKE_UNITY_BUILD ON)
set(CMAKE_UNITY_BUILD_BATCH_SIZE 16) # Tune per project
```
### Parallel Linking
```cmake
# Use mold or lld for faster linking
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=mold") # or -fuse-ld=lld
```
### Link-Time Optimization (LTO)
```cmake
# Interprocedural optimization for release builds
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
```
## compile_commands.json
Essential for IDE integration, clang-tidy, and clangd:
```cmake
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
```
```bash
# Symlink to project root for IDE/tool discovery
ln -sf build/debug/compile_commands.json compile_commands.json
```
### clangd Configuration (.clangd)
```yaml
CompileFlags:
CompilationDatabase: build/debug
Add: [-Wall, -Wextra, -Wpedantic]
Remove: [-W*] # Optional: suppress noisy warnings in editor
Diagnostics:
UnusedIncludes: Strict
ClangTidy:
Add: [modernize-*, performance-*, bugprone-*, readability-braces-*]
Remove: [modernize-use-trailing-return-type]
InlayHints:
Enabled: true
ParameterNames: true
DeducedTypes: true
```
## Dependency Management
### vcpkg (Recommended for large projects)
```json
// vcpkg.json (manifest mode)
{
"name": "my-project",
"version-semver": "1.0.0",
"dependencies": [
"fmt",
"spdlog",
"eigen3",
{ "name": "gtest", "features": ["gmock"] },
{ "name": "benchmark", "features": [] }
],
"builtin-baseline": "2024.01.12"
}
```
```cmake
# CMake toolchain integration
cmake --preset debug -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/builtin/vcpkg.cmake
```
### Conan 2.x
```ini
# conanfile.txt
[requires]
fmt/10.2.1
spdlog/1.13.0
gtest/1.14.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
```
```bash
conan install . --build=missing --profile=default
cmake --preset conan-release
```
### FetchContent (Lightweight deps only)
```cmake
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(googletest)
```
## Static Analysis Pipeline
### .clang-tidy
```yaml
Checks: >
-*,
bugprone-*,
cert-*,
cppcoreguidelines-*,
misc-*,
modernize-*,
performance-*,
readability-*,
-modernize-use-trailing-return-type,
-readability-identifier-length,
-cppcoreguidelines-avoid-magic-numbers,
-readability-magic-numbers,
-misc-non-private-member-variables-in-classes
WarningsAsErrors: >
bugprone-use-after-move,
bugprone-dangling-handle,
cppcoreguidelines-owning-memory,
performance-unnecessary-copy-initialization
HeaderFilterRegex: 'include/.*\.hpp$'
FormatStyle: file
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberSuffix
value: '_'
```
### cppcheck Configuration
```bash
# Project-level suppression file: .cppcheck-suppress
unmatchedSuppression:*
missingIncludeSystem
useStlAlgorithm:*/test/*
# Run with project config
cppcheck --project=build/debug/compile_commands.json \
--suppressions-list=.cppcheck-suppress \
--enable=warning,performance,portability \
--inline-suppr \
--error-exitcode=1 \
-j$(nproc)
```
### include-what-you-use (IWYU)
```bash
# Run IWYU via CMake
cmake -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--mapping_file=iwyu.imp" ..
cmake --build build 2>&1 | fix_includes.py
```
### Full Analysis Pipeline Script
```bash
#!/bin/bash
set -euo pipefail
BUILD_DIR="build/debug"
echo "=== clang-format check ==="
find src include -name '*.cpp' -o -name '*.hpp' | xargs clang-format --dry-run -Werror
echo "=== clang-tidy ==="
run-clang-tidy -p "$BUILD_DIR" -j$(nproc) 'src/.*\.(cpp|hpp)$'
echo "=== cppcheck ==="
cppcheck --project="$BUILD_DIR/compile_commands.json" \
--enable=warning,performance,portability \
--error-exitcode=1 -j$(nproc)
echo "=== build + test ==="
cmake --build "$BUILD_DIR" -j$(nproc)
ctest --test-dir "$BUILD_DIR" --output-on-failure
echo "=== All checks passed ==="
```
## Physical Design for Large Codebases
### Layer Architecture
```
project/
├── include/project/
│ ├── core/ # Layer 0: No internal deps
│ │ ├── types.hpp # Fundamental types, concepts
│ │ ├── error.hpp # Error types (std::expected)
│ │ └── config.hpp # Configuration
│ ├── math/ # Layer 1: Depends on core only
│ │ ├── vector.hpp
│ │ ├── matrix.hpp
│ │ └── solver.hpp
│ ├── domain/ # Layer 2: Depends on core + math
│ │ ├── mesh.hpp
│ │ ├── field.hpp
│ │ └── boundary.hpp
│ └── app/ # Layer 3: Depends on all below
│ ├──Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.