(A Basic) Introduction to CMake

Last update: 05 Jul 2023 [History] [Edit]

This page provides a (hopefully) easy-to-follow introduction to using CMake for building ATLAS code. It explains how to set up the configuration of a CMake (analysis) project, and how to configure the build of individual “packages” inside the project

CMake Basics

CMake is a high-level language for describing the build instructions for a piece of software. It is developed by Kitware, and can be accessed on https://cmake.org. It is used as the build system of software products of many types and sizes. Including the software provided by Netflix, KDE, or ROOT.

CMake itself is not responsible for running the tools that build software. It’s not a replacement of GNU Make and similar tools. Instead it’s a layer on top of these tools. CMake is responsible for generating the proper configuration for lower level tools for actually building a software project. On UNIX systems this by default means generating makefiles that take care of the build itself. But CMake supports a large set of backends. Including a large set of different Integrated Development Environments (IDEs).

ATLAS Code Layout

For all of the ATLAS code we use “out of source” building. This means that we use a different directory for building our code than the directory that actually holds our code. For this reason we very often refer to what we call our “source directory” and our “build directory”. It is highly recommended that you follow this layout.

  • The “source directory” is a directory holding all of the code that we want to build. Most of the time it has a file called CMakeLists.txt in its root directory, but not in every case. (For instance the code in the offline repository atlas/athena doesn’t have a CMakeLists.txt file in its root directory. But that’s a longer story…)
  • The “build directory” is simply where we call cmake from. This is where CMake puts all of the files for the build system (usually GNU Make for building our project).