Conan a C/C++ package manager
@uilian
Conan
The barbarian
Just a
code ...
// main.cpp
#include <iostream>
#include "Poco/Net/NetworkInterface.h"
static void print_interfaces() {
using Poco::Net::NetworkInterface;
const auto interfaces =
NetworkInterface::map(false, false);
for (const auto& it : interfaces) {
std::cout << it.second.name() << ‘n’;
}
}
int main() {
print_interfaces();
}
Problem
External
dependencies
15 minutes to build!
History
Biicode
Biicode: C/C++
Dependency Manager
github.com/biicode
Conan
Features
● Free Software and Open Source;
● MIT License;
● GIT style, decentralized -
distributed;
● Handle sources and binaries;
● Generates VS, CMake, qmake, ...
foobar@khomp ~ $ sudo pip install conan
foobar@khomp ~ $ conan user
It seems to be the first time you run conan
Auto detecting your dev setup to initialize conan.conf
Found gcc 6.2
Default conan.conf settings
os=Linux
arch=x86_64
compiler=gcc
compiler.version=6.2
build_type=Release
*** You can change them in ~/.conan/conan.conf ***
*** Or override with -s compiler='other' -s ...s***
Install
Using pip
Package
Naming
Package structure:
name/version@user/channel
Example:
Poco/1.7.5@khomp/stable
Poco/1.7.5@khomp/testing
Poco/1.7.5@khomp/ci
// main.cpp
#include <iostream>
#include "Poco/Net/NetworkInterface.h"
static void print_interfaces() {
using Poco::Net::NetworkInterface;
const auto interfaces =
NetworkInterface::map(false, false);
for (const auto& it : interfaces) {
std::cout << it.second.name() << ‘n’;
}
}
int main() {
print_interfaces();
}
Example
Using Poco Network
Example
Using Poco Network
# CMakeLists.txt
project(network-interfaces CXX)
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.
cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME}
${CONAN_LIBS})
Example
Using Poco Network
# conanfile.txt
[requires]
Poco/1.7.5@lasote/stable
[generators]
cmake
foobar@khomp ~ $ mkdir build && cd build
foobar@khomp ~/build $ conan install ..
foobar@khomp ~/build $ cmake .. && cmake --build .
foobar@khomp ~/build $ bin/network-interfaces
lo
enp1s0
enp2s0
docker0
Example
Using Poco Network
Question
Package
Cached
package
Local cache
Package
How to create
from source
Conan Example
gitlab.khomp.corp/uilian/conan-example
Asciinema
https://asciinema.org/a/102922
conanfile.py
class ExampleConan(ConanFile):
name = "conan-example"
version = "0.1.0"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
exports = "*"
requires = "Poco/1.7.5@lasote/stable"
def build(self):
cmake = CMake(self.settings)
self.run('cmake %s %s' % (self.conanfile_directory,
cmake.command_line))
self.run("cmake --build . %s" % cmake.build_config)
def package(self):
self.copy("*.a", dst='lib', src='lib')
self.copy("*.hpp", dst='include', src='src')
def package_info(self):
self.cpp_info.libs = ["example"]
Package
How to create
from source
Package
How to test
Package
How to test
Project structure
Package
How to test
class TestExampleConan(ConanFile):
name = "TestExampleConan"
version = "0.1.0"
settings = "os", "compiler", "build_type", "arch"
requires = "conan-example/0.1.0@uilian/testing",
"gtest/1.8.0@lasote/stable"
generators = "cmake"
def build(self):
cmake = CMake(self.settings)
self.run('cmake %s %s' % (self.conanfile_directory,
cmake.command_line))
self.run("cmake --build . %s" % cmake.build_config)
def imports(self):
self.copy(pattern="*.a", dst="lib", src="lib")
self.copy(pattern="*.hpp", dst="include", src="include")
def test(self):
self.run("cmake --build . --target test")
foobar@khomp ~ $ conan test
● Build project
● Export sources
● Cache package
● Build test
● Import project package from cache
● Execute all tests
Example
Using Poco Network
Remote
Decentralized
Scenario: multiple remotes
Package Tools
Generate multiples
packages
Scenario: Khomp
GCC-4.8
GCC-5.4
GCC-6.2
conan-example/
0.1.0@uilian/testing
Package
How to test
# build.py
from conan.packager import ConanMultiPackager
if __name__ == "__main__":
builder =
ConanMultiPackager(username="myuser")
builder.add_common_builds()
builder.run()
OFFICIAL
https://www.conan.io/
PROJECT
https://github.com/conan-io/conan
CPPCON 2016
https://youtu.be/xvqH_ck-5Q8
https://goo.gl/zG3729
CPPCAST
https://goo.gl/
Package
Tools
Generate multiples
packages
Conan a C/C++ Package Manager

Conan a C/C++ Package Manager