Fork me on GitHub
Credit and license

Building portable code with CMake

CMake is a popular open-source, cross-platform family of tools designed to build, test, and package software.

In this lesson we will motivate the use of Make and CMake discover and apply various CMake building blocks. We will exercise applying the material by configuring and building an example mixed Fortran-C++ project using CMake.

Contributions welcome

The material is not well tested on Windows because the lesson authors are Linux/Mac people. Corrections and contributions which make the lesson more general and portable are very much welcome.

Prerequisites

  1. You need to install CMake, as well as Fortran, C, and C++ compilers.

  2. To appreciate this material it helps to have some prior exposure to Makefiles and compiled languages but we have also something for the Python/R crowd.

Schedule

09:00 Data processing pipeline using Make Why do many projects use Makefiles?
How does the make command work?
What are Makefiles composed of?
Why are Makefiles useful for Python and R developers?
09:30 Why CMake? I am already using Makefiles, do I need CMake?
What are typical problems with Makefiles?
Why CMake and not Autotools?
I am a Python developer, is any of this relevant for me?
09:35 Hello-world example using CMake How are CMake projects configured and built?
What is an out of source compilation?
09:55 Exercise: CMake-ify a Tetris game How to configure and compile a code that you found on the net.
10:05 Branching, variables, lists, and loops Is CMake a full-fledged programming language?
10:15 Help Where can I find help?
10:20 Compilers and compiler flags How can we select the compiler?
How can we change compiler flags?
10:30 Find command family How can we find programs, libraries, files, and paths with CMake?
10:35 Break
10:50 Exercise: CMake-ify an example project What is a typical layout for a CMake framework?
How can we build static and shared libraries?
How can we get version information into the binary output for reproducibility?
How does testing work in CMake?
How can we create an installer and packager?
11:45 Appetizers for more advanced concepts What else is possible?
11:50 Generators Can CMake be used with tools and frameworks other than Makefiles?
11:55 Conclusions and outlook What can we take home?
Any critical views?
What have we skipped?
12:00 Finish