CMake Build System

A short description of CMake the configuration and build system used by CamiTK project.

CamiTK is based on Kitware CMake configuration and build system generator. It is one of the most common tool for C++ open-source project.

This documentation does not explain CMake in details but gives you the minimum knowledge to start to build your CEP. Do not hesitate to read more about CMake (there are a lot of tutorials available online).

How does it work?

CMake allows the CamiTK project to use the same code on all the supported platforms (Linux, Windows and Mac/OS). It provides a GUI for its configuration on each platform. It also forces the separation between the source code and the build objects (.o, .lib…) (which is a good thing!)

CMake is a cross-platform, open-source system for managing the build process of software using a compiler-independent method.

As CamiTK is multi-platform, when you download CamiTK sources it contains a lot of CMakeLists.txt file, which CMake will use to build the source according to your operating system. For instance, it generates Makefiles for Linux and Visual Studio solutions (.sln) for Windows.

This figure shows the two steps used by CMake to build an application or the CamiTK extension:

Cmake Based

When using cmake you need to understand that:

  • the build directory and source directory are separated
  • starting from scratch it needs to be populated first by cmake, this is called the configuration phase
  • then the developer uses its own compiler toolchain to build the libraries and executable

When you modify a CMakeList.txt or add a source file to your code, you need to rerun the configuration phase for CMake to take your changes into account.

What are CamiTK CMake macros?

CamiTK provides a lot of very easy-to-use CMake macros to help you writing your extension. Most of the time you won’t need to edit the CMake configuration files (the CMakeLists.txt files).

A CMake macro is like a function that contains a lot of specific instructions.

For instance the camitk_extension(...) macro is the only thing you need to know about in order to start building a CamiTK extension.