watson-health--stacked-scrolling--1


The Role of CMake in Building Libraries - Zenoh Series

I dove into installation not knowing much about CMake. Hence, I'd actually placed some blind faith in the documentation. That turned out fine, but here's a breakdown for those who need it.

CMake is a meta-build system. It is meta because it doesn't actually compile your code, rather, it acts as a middleman between your code and a compiler/lower-level build system (like GNU Make). It dynamically provides detailed instructions to your compiler on how it should convert your source code into a binary executable. You guide CMake on how it can do this using a CMakeLists.txt file.

In the CMakeLists.txt, you specify things like:

This way, instead of running the same long set of commands to your build system/compiler, CMake creates a layer of abstraction for developers.

Now that we understand this basic fact, we can break down what's happening in step 3.

  1. First, we create a build directory that sits outside the source directory (the repository we cloned). (it's good practice to separate the build and source)
  2. Once we cd to the build directory, we are calling cmake onto the zenoh-c source directory, where sits a CMakeLists.txt file.
  3. Based on this file, CMake will carry out its duty in generating configuration files.
  4. Then, we tell it to build the project within our build directory
  5. Lastly, we install the built program into our system, i.e. copy the built files and configure it such that it becomes more globally accessible.