Converting a C++ project to CMake & Conan

Marco Massenzio
The Startup
Published in
4 min readMar 20, 2020

--

This post describes how to fully automate the build/install of a C++ Project, with several dependencies, using CMake and Conan, a package manager.

Credit: Stefan Keller (https://pixabay.com/photos/fantasy-light-mood-sky-beautiful-2861107/)

A couple of years back, I needed a simple HTTP client to run some integration tests against a Gossip Server I was developing; it turns out that, something we take for granted in Java, is a rather complicated matter to obtain for a C++ project: I eventually found SimpleHttpRequest and decided to give it a spin.

However, if you look at the project how it was back then it was still a pretty cumbersome build process, including, among other things, cloning three sub-modules, and then building and installing them manually.

Enter Conan

Conan is an open-source project that simplifies building C++ libraries that your own project depends upon, across binary platforms and without having to really to dig into the intricacies of how each library build is designed.

SimpleHttpRequest had three dependencies which it imported directly into the repository ( http-parser, libuv and opensssl), the conanfile.txt required to download and build them would be something like this:

[requires] 
openssl/1.1.1d
libuv/1.31.0@bincrafters/stable
http_parser/2.9.2

--

--