When I first started learning CMake, I was surprised at how few tutorials and good references exist on the internet. Here’s a list of resources that I have found to be helpful.
Note: Since we originally published this article, we also created a course that teaches you modern CMake, as well as a course for intermediate and advanced users on creating a reusable CMake project skeleton.
Table of Contents:
Learning CMake
- Effective Modern CMake
- An Introduction to Modern CMake
- It’s Time to do CMake Right
- CGold: The Hitchhiker’s Guide to CMake
- CMake by Example
- CMake Tutorial (Seven part series)
- Tutorial: Easily supporting CMake install and find_package()
- Tutorial: Easy dependency management for C++ with CMake and Git
- CMake FAQ
- CMake on Stack Overflow
Video
- Mathieu Ropert: Using Modern CMake Patterns to Enforce a Good Modular Design
- Deniz Bahadir: More Modern CMake
- Tutorial Series
Audio
- CPPCast: Professional CMake – Rob and Jason are joined by Craig Scott. They first discuss a recent blog post from PVS-Studio analyzing some bugs in CMake. Then Craig talks about how he got involved in CMake development, and his e-book ‘Professional CMake: A Practical Guide.’
Cheat Sheets
Documentation
Dependency Management
Packaging
Project Skeletons
- CrustyAuklet/seal-test – Blinky CMake skeleton for an embedded target
- Uses CMSIS as a CMake module
- cortexm/baremetal– ARM Cortex-M bare-metal example code in C++ with a CMake build system
List of Global Variables
CMAKE_BINARY_DIR- Same as
CMAKE_SOURCE_DIRfor in-source builds - Otherwise, top-level directory of your build tree
- Same as
CMAKE_SOURCE_DIR- Top-level source directory
EXECUTABLE_OUTPUT_PATH- Set this variable to specify where executables should be placed (instead of
CMAKE_CURRENT_BINARY_DIR) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
- Set this variable to specify where executables should be placed (instead of
LIBRARY_OUTPUT_PATH- Set this variable to specify where libraries should be placed (instead of
CMAKE_CURRENT_BINARY_DIR) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
- Set this variable to specify where libraries should be placed (instead of
PROJECT_NAME- The name of the project set by the
project()command
- The name of the project set by the
PROJECT_SOURCE_DIR- Full path to the root of your project source directory (nearest directory where CMakeLists.txt contains the
project()command
- Full path to the root of your project source directory (nearest directory where CMakeLists.txt contains the
Want to Learn CMake?
Our course provides a hands on approach for learning CMake. You’ll create a build system for a complex project that supports multiple processor architectures, toolchains, and operating systems.
