Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Conan, C++ and the elephant in the room
Industrial Engineer
Software developer
Robotics | 3D printing | Automation
danimtb
@Dani_MTB
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
"De lo que nos rodea, ¿qué ha sido escrito en C++?"
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Librerías y frameworks:
Build systems:
Compiladores:
Sistemas operativos:
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
¿What is this Conan thing and what's up with package management?
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Dependency management in C++
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Dependency management in C++
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Dependency management in C++
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Dependency management in C++
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Language dependency (package) manager
$ git clone <URL>
$ pip install -r requirements.txt
$ python app.py
$ git clone <URL>
$ npm install
$ npm start/app.js
$ git clone <URL>
$ mvn install
$ java app.jar
$ git clone <URL>
$ cat readme.md
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Hands-on example:
Camera demo: face recognition
=============================
OpenCV provides a really powerful library and easy to use set of
features related to image processing. This example performs a simple
**face recognition** over a camera feed.
In this example we are using `opencv/3.4.5` and CMake.
Steps to build and run the example:
```
# Create a build folder
$ mkdir build
$ cd build
# Install dependencies
$ conan install ../conanfile.txt
# Compile as usual with CMake
$ cmake .. -G "Visual Studio 15 2017 Win64"
$ cmake --build . --config Release
# Run the application
$ cd bin
$ camera
```Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Language dependency (package) manager: conan.io
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Conan C/C++ package manager
- Works for Windows and Linux?
All platforms
Windows, Linux, Apple, FreeBSD, Android, iOS, embedded, cross-building, etc.
- I use CMake, Makefiles & Visual Studio: do I have to change my build system?
All build systems
Visual Studio MSBuild, CMake, Makefiles, SCons, etc. Extensible to any build system.
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Conan C/C++ package manager
- I don't want to compile every time
Full binaries management
Create, manage and reuse any number of binaries, for any configuration: platform, compiler, version, architectures… or build from sources at will.
- I want to share my own packages with my teammates
Decentralized client-server system
JFrog Artifactory on-prem to fully own your packages and binaries.
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Reference: Name and version of the library
opencv/3.4.5
Linux, x86_64, GCC 6, Release, shared=True... opencv/3.4.5:008f1a2b119556f550c11... Linux, x86_64, GCC 6, Debug, shared=False... opencv/3.4.5:160c0f76fcf1ad0d80837...
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Generators:
Translate information of depencies in the graph to a suitable format for your build system
Profiles:
Gather settings, options, env vars... that are used as input
Build helpers:
Translate input information to build system flags/commands
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
from conans import ConanFile, CMake
class HelloLib(ConanFile):
name = "hellolib"
version = "0.0.1"
url = "https://this/is/an/example"
homepage = "https://example.com"
author = "danimtb"
topics = "demo", "lib"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False]}
default_options = {"shared": False}conanfile.py: Metadata and settings
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
from conans import ConanFile, CMake
class HelloLib(ConanFile):
...
exports_sources = "include/*", "src/*", "CMakeLists.txt", "readme.md"
# scm = {"type": "git",
# "revision": "auto",
# "url": "auto"}
# def source(self):
# # Write your own function
# tools.get(url="...", sha1="...")
# os.rename("name-version", "source_folder")conanfile.py: Sources
from conans import ConanFile, CMake
class HelloLib(ConanFile):
...
#exports_sources = "include/*", "src/*", "CMakeLists.txt", "readme.md"
scm = {"type": "git",
"revision": "auto",
"url": "auto"}
# def source(self):
# # Write your own function
# tools.get(url="...", sha1="...")
# os.rename("name-version", "source_folder")from conans import ConanFile, CMake
class HelloLib(ConanFile):
...
#exports_sources = "include/*", "src/*", "CMakeLists.txt", "readme.md"
# scm = {"type": "git",
# "revision": "auto",
# "url": "auto"}
def source(self):
# Write your own function
tools.get(url="...", sha1="...")
os.rename("name-version", "source_folder")Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
from conans import ConanFile, CMake, tools
class HelloLib(ConanFile):
...
# generators = "cmake", "cmake_find_package"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()conanfile.py: Building
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
from conans import ConanFile, CMake
class HelloLib(ConanFile):
...
def package(self):
cmake = CMake()
cmake.configure()
cmake.install()
self.copy("readme.md", dst=".")conanfile.py: Package
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
from conans import ConanFile, CMake
class HelloLib(ConanFile):
...
def package_info(self):
self.cpp_info.libs = ["hellolib"]
self.cpp_info.defines = ["WITH_HELLO_LIB"]conanfile.py: Information for consumers
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
$ conan create conanfile.py --profile=gccCreate the packages for any configuration
Upload them to your server
$ conan upload name/version@ --all --remote=my-remoteMeetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Community Edition for C/C++
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
20% discount code for the talks
Ask us to get it for free!
Conclusion
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Meetup Madrid C/C++ | Daniel Manzaneque — @Dani_MTB
Conan, C++ and the elephant in the room