Published on

Using CMake

Authors

Today I came across a project that used CMake. You can tell a project uses CMake as it will have a CMakeLists.txt file in the root of the project. Looking at the CMake site it is not immediately clear how to use it. After a bit of Googling I came across this excellent blog post that gets you up and running pretty fast. Based on this blog post CMake works as follows:

  • You define your build steps in a CMakeLists.txt file
  • CMake has the concept of generators which are alternate build system files that CMakeList.txt is converted to when running cmake
  • The default generator (when not specifying one) is make as in makefiles

The easiest way to run CMake in a project that has it is:

  • Go to the root of the project
  • Create a new directory and cd into it e.g.
mkdir build && cd &_
  • Run cmake which generates a makefile and meta data in the _build directory
cmake ..
  • Finally run make:
make
sudo make install
Note
  • You may not have to sudo depending on what you are installing
  • If you are running this in a DockerFile you do not need to and cannot run commands as sudo