
Explore static versus shared libraries, how linking affects executable size and runtime requirements, and how cmake add_library handles library types, including object libraries for common code, Unix, Windows, and macOS.
Learn to build a basic library with cmake, build two executables, switch between Make and Ninja generators, and link executables to static or shared libraries.
Learn basic cmake variables and script mode, define and retrieve variables with set and ${VAR}, handle undefined values, unset variables, and build semantic version strings with major, minor, and patch.
Explore how to define options in cmake using the option command, treat options as boolean cache variables, and use cmake-gui to edit and generate builds, with internal variables hidden.
Explore string manipulation in CMake by using the string command to find and replace substrings, convert to lower case, and leverage sub comments, match options, and regular expressions.
Demonstrates using if statements in CMake, including true/false evaluation, handling non-existing variables and empty strings, and testing packages with find_package and the found variables.
Master loop constructs in cmake, including for each and while, using lists and the items keyword, with break and continue for flow control.
Explore CMake loops using for each over lists a and b, combining items, customizing loop variable names, and using range semantics similar to C++ to control start and end values.
We will shortly go over the project that we will build upon in the next lectures
We see what happens to variables inside subfolders + how to use PARENT_SCOPE
Learn to configure include directories with target_include_directories in cmake, using public vs private scopes and angle brackets versus quotes to share headers across targets.
We use functions and target_compiler_options()
We learn what a macro is and how it's different from a function
We treat optional arguments using ARGC, ARGV and ARGN
We use cmake_parse_arguments to make a function with keyword arguments (or named arguments)
We continue our example by reading the version string from the file and setting the output variables
We compare include() with add_subdirectory() and explore some CMake predefined variables, like CMAKE_CURRENT_SOURCE_DIR, CMAKE_CURRENT_LIST_DIR and so on.
We will use install() to copy our header files into the install location
We will call install() with the EXPORT keyword and generate a config file which we later use with find_package
We are creating a small project which uses our old sortdemo project. We call find_package() for that
We will add a namespace to our export, install a binary and play around with CMAKE_PREFIX_PATH. CMAKE_MODULE_PATH is also (very) briefly shown.
Explore methods to integrate third-party libraries into a CMake project, including fetch content, adding subdirectories for CMake projects, using pkg-config for non-CMake projects, and creating a custom find module.
We pull GoogleTest with FetchContent to see how to get dependencies with FetchContent
We use pkg-config to find flags that we need to pass to compilers. Next we use pkg-config in CMake to link to the libraries and set include folders.
We demonstrate how to use find_library and find_path
We look at how to write our own find module.
We call find_package with "Threads" to build an example with threads.
We call enable_testing() and add_test() to add some tests in CMake
We customize our tests with set_tests_properties()
This course is for C++ developers and computer science students and it helps with the frustration of learning CMake by providing a structured way of doing it, using small "Hello World"-like examples and some real world examples as well.
If you're like me, you were frustrated because there is no structured tutorial that goes beyond the absolute basics. Maybe you even hated CMake, like a lot of programmers. This will be taken care of, because this is a structured learning path, and we will cover some of the most frequently used features of CMake.
No prior experience with CMake is needed, but basic C++ is needed. Just the basics, nothing fancy.
I've been a professional software developer for more than 10 years now. I've also been a trainer in one of my jobs. I noticed that it's better to take a hands-on approach and I encourage you to do the same with this course. Play around with the examples. Break them. See what happens.
What you'll get out of this:
CMake is cross-platform
It's in a lot of open-source projects, (maybe even your work projects) which you'll understand better
Simple, easy to follow examples, some of them inspired by real projects
Write your own CMake projects:
Build
Export
Use 3rd party libraries
Test
Mostly Linux examples, some Windows ones
Windows setup in CLion, Visual Studio, the command line + cmake-gui
Here's a rough outline of the course, but please look at the curriculum on this page:
CMake basics
Variables
Control Flow
Structuring your projects
Export
External dependencies
Testing with CTest