Master modern, target‑based CMake to configure, build, test, and package C++ projects cleanly.
Understand generators (Ninja, Makefiles), toolchains, and policies; write robust find_package
configs and export reusable targets.
Manage external dependencies with FetchContent
and ExternalProject
, and integrate testing with CTest/CDash.
Gain practical experience through hands‑on labs (~70%) that mirror real‑world codebases.
How CMake helps: portability across platforms/compilers, reproducible builds, clear dependency graphs, and smooth CI/CD packaging with CPack.
Who it’s for: designed for individuals with experience in C++ or C who want to adopt modern CMake practices in production teams.
By the end you’ll confidently structure projects, debug/troubleshoot CMake, and scale to advanced topics (CUDA, MPI, cross‑compiling).
Curriculum
Welcome and setup
- Ensure development setup for C++ and CMake
- Basic CMake installation and setup
CMake introduction
- Overview of CMake and its role in modern build systems
- CMake’s major features and benefits
- Understanding the CMake workflow
- Source configuration
- Build system generation
- Build execution
CMake workflow
- CMake configuration workflow
- Writing your first CMakeLists.txt
- Configuring and generating a build system
- Running CMake from the command line and IDEs
- Understanding CMake generators (Makefiles, Ninja, etc.)
Building libraries and executables
- Defining and managing targets in CMake
- add_executable and add_library
- Linking libraries and dependencies
- target_link_libraries
- Variables in CMake: regular vs. cache variables
- Managing build configurations with CMake variables
- Overview of modern CMake’s target-centric approach
- Best practices for building and organizing projects
- Compiler and compiler options specification
- Language standard specifications
- Detect and work with environment variables
- Detect and work with various CPU architectures
More CMake syntax
- CMake syntax and supported commands
- Control flow in CMake scripts (if, foreach, while)
- Using generator expressions ($<...>) for conditional logic
- Target properties and advanced target management
- Installing targets and creating installation rules
- Practical hands-on tips and tricks
Importing and exporting targets
- Creating exportable targets with install(EXPORT)
- Using find_package() and writing Config files
- Importing third‑party targets and managing dependencies
- Best practices for reusable and portable CMake configurations
External Project and FetchContent
- Introduction to external project management in CMake
- Using ExternalProject_Add for building external dependencies
- Overview of FetchContent for simplifying dependency management
- Practical examples and use cases
CMake’s policy system
- Understanding the CMake policy system
- Handling policy warnings and errors
- Adopting best practices for policy management
- Noteworthy changes from recent CMake releases
Debugging and profiling CMake scripts
- Debugging with message() and cmake --trace
- Profiling CMake builds to optimize performance
- Understanding and resolving common CMake issues
Companion tools and testing framework
- Writing and running tests with CTest
- Integrating test coverage and dynamic analysis tools
- Introduction to CDash for continuous integration and testing
- Overview of the packaging tool: CPack
- Practical exercises with CTest and CPack
Advanced topics in CMake
- CMake support for MPI (Message Passing Interface)
- Setting up and managing MPI projects
- CUDA support in CMake
- Building CUDA applications with CMake
- Cross compilation with CMake
- Setting up toolchains and cross‑compiling projects
- Fortran support in CMake
- Configuring and building Fortran projects
Course Day Structure
- Part one: 09:00–10:30
- Coffee break: 10:30–10:45
- Part two: 10:45–12:15
- Lunch break: 12:15–13:15
- Part three: 13:15–15:15
- Coffee break: 15:15–15:30
- Part four: 15:30–17:30