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:
- Project Name
- Project Dependencies (include and link directories)
- Project Files/Organisation (very useful when it comes to larger projects)
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.
- First, we create a
builddirectory that sits outside the source directory (the repository we cloned). (it's good practice to separate the build and source) - Once we
cdto the build directory, we are callingcmakeonto thezenoh-csource directory, where sits aCMakeLists.txtfile. - Based on this file, CMake will carry out its duty in generating configuration files.
- Then, we tell it to build the project within our build directory
- 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.