Before installation, there are some key points about Conan:
“Conan is a dependency and package manager for C and C++ languages.”
“With full binary management, Conan can create and reuse any number of different binaries (for different configurations like architectures, compiler versions, etc.) for any number of different versions of a package, using exactly the same process in all platforms.”
“As it is decentralized, it is easy to run your own server to host your own packages and binaries privately, without needing to share them.”
On the server side: “The free JFrog Artifactory Community Edition (CE) is the recommended Conan server to host your own packages privately under your control.”
On the client side: What one needs is a Conan client.
Simply put, JFrog for server and Conan for client.
“Conan is a decentralized package manager with a client-server architecture. This means that clients can fetch packages from, as well as upload packages to, different servers (“remotes”), similar to the “git” push-pull model to/from git remotes.”
“At a high level, the servers are just storing packages. They do not build nor create the packages. The packages are created by the client, and if binaries are built from sources, that compilation is also done by the client application.”
“The Conan client: this is a console/terminal command-line application, containing the heavy logic for package creation and consumption. Conan client has a local cache for package storage, and so it allows you to fully create and test packages offline. You can also work offline as long as no new packages are needed from remote servers.”
“JFrog Artifactory Community Edition (CE) is the recommended Conan server to host your own packages privately under your control. It is a free community edition of JFrog Artifactory for Conan packages, including a WebUI, multiple auth protocols (LDAP), Virtual and Remote repositories to create advanced topologies, a Rest API, and generic repositories to host any artifact.”
“ConanCenter is a central public repository where the community contributes packages for popular open-source libraries like Boost, Zlib, OpenSSL, Poco, etc.”
The basic unit of conan project is a package. And a package is defined by a file “conanfile.py” that defines the package’s dependencies, sources, how to build the binaries from sources, etc. One package “conanfile.py” recipe can generate any arbitrary number of binaries, one for each different platform and configuration: operating system, architecture, compiler, build type, etc.
“These binaries can be created and uploaded to a server with the same commands in all platforms, having a single source of truth for all packages and not requiring a different solution for every different operating system.”
“Installation of packages from servers is also very efficient. Only the necessary binaries for the current platform and configuration are downloaded, not all of them. If the compatible binary is not available, the package can be built from sources in the client too.”
An example about conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
classHelloConan(ConanFile):
name ="hello"
version ="0.1"# Optional metadata
license ="<Put the package license here>"
author ="<Put your name here> <And your email here>"
url ="<Package recipe repository url here, for issues about the package>"
description ="<Description of Hello here>"
topics =("<Put some tag here>","<here>","<and here>")# Binary configuration
settings ="os","compiler","build_type","arch"
options ={"shared":[True,False],"fPIC":[True,False]}
default_options ={"shared":False,"fPIC":True}# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources ="CMakeLists.txt","src/*","include/*"defconfig_options(self):if self.settings.os =="Windows":del self.options.fPIC
deflayout(self):
cmake_layout(self)defgenerate(self):
tc = CMakeToolchain(self)
tc.generate()defbuild(self):
cmake = CMake(self)
cmake.configure()
cmake.build()defpackage(self):
cmake = CMake(self)
cmake.install()defpackage_info(self):
self.cpp_info.libs =["hello"]