Course in CMake

Course in C/C++ application build using CMake

CMake has emerged as the most popular build tool for C/C++ applications and libraries. The reason is that CMake actually is a build script generator for Make, Ninja, MSVSC++, Xcode and more. This provides a lot of flexibility regarding usage of tools and editors.

This course focuses on that you quickly get up and running creating and working with CMake based C/C++ projects.
This is what you will learn
  • Configure CMake for C/C++ projects
  • Configure build of executables
  • Configure build of static libraries
  • Configure build of shared libraries
  • Link external libraries
  • Download automatically and link remote libraries
  • Generate source code
  • Execute various tools as part of the build
Course Contents

Background

  • Why CMake was created
  • Properties of CMake
  • Compilers
  • Build tools
  • Build tool generators

Understanding Compilation and Linkage Steps

  • Using GCC
  • Pre-processor
  • Front-End compilation
  • AST and RTL
  • Back-end compilation
  • Assembler
  • Linker
  • Loader
  • Useful compiler flags
  • Linking libraries
  • Creating static libraries
  • Creating shared libraries
  • Executing with shared libraries

Brief about Makefiles

  • What is make
  • Structure of a Makefile
  • Targets
  • Actions
  • Dependencies
  • Rules
  • Ninja instead of Make

Installation of CMake

  • Installation via a package manager
  • Installation on Windows
  • Installation via TAR.GZ archive
  • Compiling from sources
  • CMake executables
  • CMake command-line help
  • CMake documentation

CMake Syntax

  • Structure of CMakeLists.txt
  • CMake stages
  • Comments
  • Command syntax
  • Text strings
  • Quoted vs. unquotes strings
  • Value lists
  • Variables
  • Conditional blocks
  • Looping blocks
  • CMake scopes
  • Subdirectories and includes
  • CMake GUI

Building Executables

  • Creating a CMake project
  • Build steps and commands
  • Programming language
  • Language standard
  • Compiler options
  • Linking standard libraries

Configure Build Variants

  • Debug vs. Release build
  • C++ vs. C sources
  • GCC vs. CLang compiler
  • Make vs. Ninja builder
  • Linux vs. Windows build

Building Libraries

  • Building a static library
  • Where to find the *.a file
  • Building a shared library
  • Where to find the *.so file
  • Propagating header files to an executable
  • Defining an object library
  • Defining a header-only library
  • Using an imported library

Linking External Libraries

  • What is an external library
  • Finding libraries
  • Configuration variables

Linking Remote Libraries

  • What is a remote library
  • Downloading and linking a remote library
  • Understanding FetchContent
  • Fetching a GIT library
  • Fetching a TAR.GZ file

Configuring and Running Tests

  • How cmake perceives a test
  • Using CTest
  • Configuring a simple test
  • Configuring a test based on a header-only testing framework (Catch2)
  • Configuring a test based on a linked testing framework (Google Test)
  • Fetching and using a remote test framework

Generating Sources

  • Copying files
  • Variable substitution
  • Managing application version
  • Assembling build info

Running External Programs

  • Custom targets
  • Running the generated executable
  • Running arbitrary scripts and programs
  • Generating API documentation using doxygen
Facts
NameCMake
Duration2 Days
LevelBeginner
AudienceC/C++ developers working in a *NIX environment
Prerequisites Experience of building C/C++ applications using a command-line compiler
Tools
  • Windows 10 or Windows 7
  • Ubuntu Linux @ VirtualBox or WSL @ Windows-10
  • GNU C/C++, CLang and MSVSC++
  • Make and Ninja
  • CMake
  • Catch2 and Google Test
  • Jetbrains CLion
On-Site Course

If you order an On-Site course, we will come to you and hold the course in your office. The price is determined by our price model and is based on the number of course days, number of participants and any travel and lodging.

Read more about out price modell and term of sales here.

Related Courses
CourseDaysLevel
Make1Beginner Show
Modern C++5BeginnerShow
BASH Shell Scripts Programming1Beginner Show