Table of Contents
Front Matter- Preface
- Who This Book Is For
- What You Need
- How This Book Is Organized
- Conventions
- The Build Health Ledger
Chapter 1: How CMake Actually Works
- 1.1 Configure, generate, and build: the three phases and what happens in each
- 1.2 Generators: Ninja, Make, Visual Studio, and Xcode
- 1.3 The cache, variables, and scope rules
- 1.4 The CMake language: lists, functions, macros, and their traps
Chapter 2: Modern Target-Based CMake
- 2.1 Targets as the unit of everything
- 2.2 Usage requirements: PUBLIC, PRIVATE, and INTERFACE
- 2.3 Generator expressions without the confusion
- 2.4 Legacy anti-patterns and how to remove them
Chapter 3: Structuring Real Projects
- 3.1 Directory layout and add_subdirectory
- 3.2 Static, shared, object, and interface libraries
- 3.3 Symbol visibility and export headers
- 3.4 Options, feature toggles, and configuration headers
- 3.5 Mixed-language targets: CUDA as a first-class language
Chapter 4: Presets and Toolchains
- 4.1 CMakePresets.json and CMakeUserPresets.json
- 4.2 Toolchain files
- 4.3 Managing compilers and flags without global pollution
- 4.4 Build types and multi-config generators
Chapter 5: Consuming Dependencies
- 5.1 find_package: config mode vs. module mode
- 5.2 FetchContent
- 5.3 vcpkg integration
- 5.4 Conan integration
- 5.5 Dependency providers: one place to decide where dependencies come from
Chapter 6: Producing Packages Others Can Consume
- 6.1 install() and export sets
- 6.2 Package config files with CMakePackageConfigHelpers
- 6.3 Versioning and compatibility rules
- 6.4 Relocatable packages
- 6.5 Shipping Python extension modules with nanobind and scikit-build-core
Chapter 7: Fixing Dependency Hell
- 7.1 Diamond dependencies and ODR violations
- 7.2 Version conflicts across the dependency graph
- 7.3 Transitive dependency leakage
- 7.4 Debugging find_package with --debug-find
- 7.5 CMake 4 and the policy floor: when old dependencies stop configuring
Chapter 8: Fast Builds
- 8.1 Ninja and build parallelism
- 8.2 Compiler caching with ccache and sccache
- 8.3 Precompiled headers
- 8.4 Unity builds and their trade-offs
Chapter 9: Diagnosing Slow Builds
- 9.1 -ftime-trace and ClangBuildAnalyzer
- 9.2 Visualizing build timelines with ninjatracing
- 9.3 Header dependency hygiene
- 9.4 Link time: lld, mold, and split DWARF
Chapter 10: C++ Modules in CMake
- 10.1 FILE_SET CXX_MODULES and module targets
- 10.2 Dependency scanning and build ordering
- 10.3 import std: standard library modules in C++23
- 10.4 Migrating an existing codebase to modules
Chapter 11: Cross-Compilation
- 11.1 Toolchain files for ARM and embedded targets
- 11.2 Sysroots and finding target dependencies
- 11.3 Android and iOS builds
- 11.4 Windows and MSVC specifics
- 11.5 WebAssembly with Emscripten, and Apple universal binaries
Chapter 12: Testing and Code Quality
- 12.1 CTest and test organization
- 12.2 Integrating sanitizers and coverage
- 12.3 Static analysis with CMAKE_CXX_CLANG_TIDY
- 12.4 compile_commands.json and tooling integration
- 12.5 Fuzzing targets with libFuzzer
- 12.6 Machine-readable diagnostics: SARIF for CI annotations
Chapter 13: Code Generation and Custom Commands
- 13.1 add_custom_command and add_custom_target
- 13.2 Generating sources at build time
- 13.3 Protobuf and gRPC integration
- 13.4 Correct dependencies for generated files
Chapter 14: CI and Reproducible Builds
- 14.1 CMake in CI pipelines
- 14.2 Build caching in CI
- 14.3 Reproducible builds: deterministic outputs and path remapping
- 14.4 Packaging and distribution with CPack
- 14.5 SBOMs, license tracking, and code signing
Chapter 15: CMake at Scale
- 15.1 Monorepos and large target graphs
- 15.2 Superbuilds and ExternalProject
- 15.3 Debugging CMake itself with --trace and the CMake debugger
- 15.4 Migrating from legacy CMake and other build systems
- Appendix A: CMake Command and Property Reference
- Appendix B: Generator Expression Reference
- Appendix C: Toolchain and Preset Templates
- Appendix D: Build Health Checklist