Conan Package Manager for C++

https://docs.conan.io/en/latest/getting_started.html contains a good introduction to Conan.

Installing Conen on MacOS can be done via brew:

brew update
brew install conan

Conan is controlled by a file called conanfile.txt. It is comparable to a maven pom or the package.json file for the node package manager.

The conanfile.txt from the tutorial that works with CMake is duplicated below

[requires]
Poco/1.9.0@pocoproject/stable

[generators]
cmake

You can now execute conan install in the folder that contains the conanfile.txt to exceute Conan. It will install all dependencies and call all generators listed in the conanfile.txt.

If Conan fails to download precompiled binaries, sometimes it is possible to tell conan to build the depencencies from code:

conan install Poco/1.9.0@pocoproject/stable --build missing

To use Conan in combination with CMake, the conanfile.txt has to create a conanbuildinfo.cmake file using a generator for CMake. That file is then used from within CMake’s CMakeLists.txt file. When CMake builds the project, it is able to call Conan.

A CMakeLists.txt file that imports the generated conanbuildinfo.cmake is given below:

cmake_minimum_required (VERSION 2.6)

project (PocoTest)

add_definitions("-std=c++11")

include(${PROJECT_SOURCE_DIR}/build/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(PocoTest PocoTest.cpp)
target_link_libraries(PocoTest ${CONAN_LIBS})

I think the workflow now is, whenever you need a new library in your project, add the dependency to Conans conanfile.txt. Then call conan install so Conan can download and install the new dependency and also generates an updated conanbuildinfo.cmake for CMake. Then build your project using CMake to include the newly provided dependencies.

Leave a Reply