Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Conan, C++ and the elephant in the room

Daniel Manzaneque Amo

 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++?"

Pregunta a Bjarne Stroustrup en una entrevista para El País

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Librerías y frameworks:

  • ROS
  • Neurocheck
  • OpenCV
  • Halcon
  • Qt
  • VTK
  • Boost

Build systems:

  • Make
  • CMake
  • QMake
  • Visual Studio

Compiladores:

  • gcc
  • msvc
  • mingw

Sistemas operativos:

  • Windows
  • Linux

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

  • C++ 11
  • STL
  • Smart Pointers
  • Lambda expressions
  • Metaprogramming
  • TDD
  • cross-building
  • (No VCS)
  • Long compile times
  • #include header hell
  • 3rd party libraries
  • git submodules hell
  • CI?
  • Nightly builds?

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++

  • No-dependencies as a feature

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Dependency management in C++

  • System package manager

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Dependency management in C++

  • git submodules

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Dependency management in C++

  • CMake install with version check
  • Delegates responsability to end user
  • Installed in system: Only one installation for all projects

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:

Face recognition

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

Basic concepts

  • Reference: Name and version of the library

opencv/3.4.5
  • Package ID: Unique identifier of the binaries

 

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

Basic concepts

  • 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

Create your own packages: hellolib

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

Create your own packages: hellolib

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

Create your own packages: hellolib

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

Create your own packages: hellolib

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

Create your own packages: hellolib

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

Create your own packages: hellolib

$ conan create conanfile.py --profile=gcc

Create the packages for any configuration

Upload them to your server

$ conan upload name/version@ --all --remote=my-remote

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

JFrog Artifactory

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

  • Use a language package manager!
     
  • Take advante of open-source packages in ConanCenter
     
  • Keep your build system
     
  • Use Artifactory for all your binaries

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Meetup Madrid C/C++  |  Daniel Manzaneque —       @Dani_MTB

Conan, C++ and the elephant in the room

Made with Slides.com