Glimpse on CmakeList — Tutorial.

Saurav Solanki
2 min readNov 2, 2022

It is hard to find a good tutorial on cmake. What is Cmake? Let’s read the definition first:

“CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.”

So what does this mean? Any software has lots of dependencies on packages, so in order to run the code, we need provide those packages for compile so that it can be bundled together and be available at run-time.

Example: Your C++ code might need OpenCV to be bundled together for capturing image from camera.

I have struggled to understand C++ code There will be situation where you need install multiple packages in C++ . There are two ways, we can tell compiler to look for pakages: CLI or use CmakeList.txt

Let’s go with best way: Cmakelist.txt

## Inside CMakeLists.txtcmake_minimum_required(VERSION 3.10)

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cpp)

Cpp files

# Inside tutorial.cpp// A simple program that print the text
#include <iostream>
int main(int argc, char* argv[])
{
// print the text
std::cout << "Hello! Cmake "< std::endl;
return 0;
}

Compile this code and voila! it runs smoothly.

# make a directory to store compiled code
>> mkdir build
>> cd build;
# configure the project and generate a native build system
>> cmake ..
# build system to actually compile/link the project
>> cmake --build .
Run the code
>> ./Tutorial
Hello! Cmake

I will be sharing more on this setup and extend its current functionality to setup Tensorflow C++ / OpenOpeno in C++ and AWS Libs. More to come with its use cases…

Meanwhile, I will also extend this to use in MLOps Application as well. Quick look: https://github.com/sauravsolanki/fastapi-docker-elk

If you like this article, please give it clap and follow me to get the updates:

I am open to opportunity and you can find me here: LinkedIn

--

--