CMake Tutorial

Published 2025 July 26

I've decided my first step to learning C++ is to learn a proper build system. Having a build system is table stakes for any C++ project. I chose CMake because it seems popular 🤷. I was delighted to find their website has a tutorial.

Once you download the tutorial files, the first exercise provides you with a small project that will compute a square root. Each exercise builds on the next and consists of fixing all the TODO:'s in the codebase. I can't say whether CMake itself is good or bad, but the tutorial rocks. I am three exercises in and getting into a flow. It has the right balance of handholding where I feel like I am still learning without missing important details. Here is the first exercise for example.

# TODO 1: Set the minimum required version of CMake to be 3.10

# TODO 2: Create a project named Tutorial

# TODO 7: Set the project version number as 1.0 in the above project command

# TODO 6: Set the variable CMAKE_CXX_STANDARD to 11
#         and the variable CMAKE_CXX_STANDARD_REQUIRED to True

# TODO 8: Use configure_file to configure and copy TutorialConfig.h.in to
#         TutorialConfig.h

# TODO 3: Add an executable called Tutorial to the project
# Hint: Be sure to specify the source file as tutorial.cxx

# TODO 9: Use target_include_directories to include ${PROJECT_BINARY_DIR}

Task based learning is my favorite form of pedagogy. Tasks are forced thought exercises which make the underlying theory apparent (or at least piques my interest enough to search for it). This tutorial may not be for everyone but it's been a lifeline for me.