CMake Tutorial — CMake 4.2.6 Documentation

# CMake Tutorial

## Introduction

The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address. Seeing how various topics all work together in an example project can be very helpful.

## Steps

The tutorial documentation and source code examples can be found in the `Help/guide/tutorial` directory of the CMake source code tree. Each step has its own subdirectory containing code that may be used as a starting point. The tutorial examples are progressive so that each step provides the complete solution for the previous step.

- Step 0: Before You Begin
  - Getting the Tutorial Exercises
  - Getting CMake
  - CMake Generators
  - Single and Multi-Configuration Generators
  - Other Usage Basics
  - Try It Out
  - Getting Help and Additional Resources
- Step 1: Getting Started with CMake
  - Background
  - Exercise 1 - Building an Executable
  - Exercise 2 - Building a Library
  - Exercise 3 - Linking Together Libraries and Executables
  - Exercise 4 - Subdirectories
- Step 2: CMake Language Fundamentals
  - Background
  - Exercise 1 - Macros, Functions, and Lists
  - Exercise 2 - Conditionals and Loops
  - Exercise 3 - Organizing with Include
- Step 3: Configuration and Cache Variables
  - Background
  - Exercise 1 - Using Options
  - Exercise 2 - `CMAKE` Variables
  - Exercise 3 - CMakePresets.json
- Step 4: In-Depth CMake Target Commands
  - Background
  - Exercise 1 - Features and Definitions
  - Exercise 2 - Compile and Link Options
  - Exercise 3 - Include and Link Directories
- Step 5: In-Depth CMake Library Concepts
  - Background
  - Exercise 1 - Static and Shared
  - Exercise 2 - Interface Libraries
  - Exercise 3 - Object Libraries
- Step 6: In-Depth System Introspection
  - Background
  - Exercise 1 - Check Include File
  - Exercise 2 - Check Source Compiles
  - Exercise 3 - Check Interprocedural Optimization
- Step 7: Custom Commands and Generated Files
  - Background
  - Exercise 1 - Using a Code Generator
- Step 8: Testing and CTest
  - Background
  - Exercise 1 - Adding Tests
- Step 9: Installation Commands and Concepts
  - Background
  - Exercise 1 - Installing Artifacts
  - Exercise 2 - Exporting Targets
  - Exercise 3 - Exporting a Version File
- Step 10: Finding Dependencies
  - Background
  - Exercise 1 - Using `find_package()`
  - Exercise 2 - Transitive Dependencies
  - Exercise 3 - Finding Other Kinds of Files
- Step 11: Miscellaneous Features
  - Exercise 1: Target Aliases
  - Exercise 2: Generator Expressions