= Conan
:toc:
:toc-placement!:

toc::[]

# Introduction

link:https://conan.io[Conan] is an open source, decentralized, and multi-platform package manager that can be used to create and share native libraries and binaries. It supports multiple build systems (CMake, Visual Studio, Makefiles) and OSes (Linux, Windows, and Mac). 

Conan servers can be installed privately or you can use public servers and packages made available by link:https://bintray.com/conan/conan-center[Jfrog bintray].

Full documentation for conan can be found from link:https://docs.conan.io/en/latest/[here]

# Installing Conan

Conan is a python application and can be installed using pip.

[source,bash]
----
$ sudo apt-get install python3 python3-pip
$ pip3 install conan
$ conan help
Consumer commands
  install    Installs the requirements specified in a recipe (conanfile.py or conanfile.txt).
...
----

Alternatively, native packages are available for most operating systems. Full details are available link:https://docs.conan.io/en/latest/installation.html[here].

# Conan Profile

In conan link:https://docs.conan.io/en/latest/reference/profiles.html#profiles[profiles] control information such as the compiler and environments that are available on your system. 

To create a new default profile run

[source,bash]
----
$ conan profile new default --detect
Found gcc 5.4
gcc>=5, using the major as version
Profile created with detected settings: /home/devuser/.conan/profiles/default
----

The generated profile will look something like:

[source,bash]
----
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=5
compiler.libcxx=libstdc++
build_type=Release
[options]
[build_requires]
[env]
----


[NOTE]
====
If you are using GCC compiler >= 5.1, Conan will set the compiler.libcxx to the old ABI for backwards compatibility. You can change this with the following commands:

[source,bash]
----
$ conan profile update settings.compiler.libcxx=libstdc++11 default  # Sets libcxx to C++11 ABI
----

[source,bash]
----
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=5
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]
----

You can find more information about this link:https://docs.conan.io/en/latest/howtos/manage_gcc_abi.html#manage-gcc-abi[here].
====

All examples provided will assume that the ABI being used for libstdc++ is the C++11 ABI.

# Finding Packages

Remote repositories can be searched for conan packages. By default the `conan-center` remote is configured. This is located in link:https://bintray.com/conan/conan-center[bintray].

## Searching for Packages

You can search for packages using the `conan search` command. For example, to search for a package such as link:https://github.com/fmtlib/fmt[fmtlib] you can run:

[source,bash]
----
$ conan search fmt* --remote=conan-center
Existing package recipes:

fmt/4.0.0@bincrafters/stable
fmt/4.1.0@bincrafters/stable
fmt/5.0.0@bincrafters/stable
fmt/5.1.0@bincrafters/stable
fmt/5.2.0@bincrafters/stable
fmt/5.2.1@bincrafters/stable
fmt/5.3.0@bincrafters/stable

----

## Inspecting Packages

You can then inspect a package using the `conan inspect` command. To inspect one one of the fmt packages from the search command above you can run:

[source,bash]
----
$ conan inspect fmt/5.3.0@bincrafters/stable --remote=conan-center
name: fmt
version: 5.3.0
url: https://github.com/bincrafters/conan-fmt
homepage: https://github.com/fmtlib/fmt
license: MIT
author: Bincrafters <bincrafters@gmail.com>
description: A safe and fast alternative to printf and IOStreams.
topics: None
generators: cmake
exports: ['LICENSE.md']
exports_sources: ['CMakeLists.txt']
short_paths: False
apply_env: True
build_policy: None
revision_mode: hash
settings: ('os', 'compiler', 'build_type', 'arch')
options:
    fPIC: [True, False]
    header_only: [True, False]
    shared: [True, False]
    with_fmt_alias: [True, False]
default_options:
    fPIC: True
    header_only: False
    shared: False
    with_fmt_alias: False
----

This shows details about the package including what link:https://docs.conan.io/en/latest/using_packages/conanfile_txt.html#options[options] can be set when including the package. In the case of fmtlib there are 4 options which allow you to specify the type of installion you want.