Build and test a modern C++ project with CMake
8 steps · about 3 h 55 min · Intermediate
- Start from CMake's guided tutorial (guide, CMake documentation, 35 min)
Learn the target-based build model through a small project before adding libraries and tests.
- Define the executable target (reference, CMake documentation, 25 min)
Name the program and attach its source files without relying on directory-wide settings.
- Extract a reusable library (guide, CMake documentation, 25 min)
Separate application entry code from logic that other targets and tests can reuse.
- Declare the required C++ standard (reference, CMake documentation, 20 min)
Ask CMake to select compatible compiler flags instead of hard-coding one toolchain's syntax.
- Enable useful diagnostics per target (reference, CMake documentation, 25 min)
Keep warning and diagnostic options scoped to code you control.
- Add a dependency deliberately (guide, CMake documentation, 35 min)
Understand package discovery and fetched dependencies before introducing third-party code.
- Register and run automated tests (reference, CMake documentation, 35 min)
Make tests part of the generated build and run them consistently with CTest.
- Create reproducible build presets (reference, CMake documentation, 35 min)
Capture configure, build and test settings for local and release workflows without machine-specific scripts.