This papar based on conan 1.x

Intro

The conan-center-index contains a lot of recipes. If you want to build everything from scratch or create conan packages on your local conan repo, you can use this recipes.

Assuming you already have some knowledge of conan and build your own conan package based on conan docs.

The conan tutorial tell you import a prebuild package like below

  • conanfile.txt style
[requires]
poco/1.9.4
  • conanfile.py style
requires = ["poco/1.9.4"]
# or
self.requires("poco/1.9.4")

Somehow, your want to build your packege with specific conan settings, such as cross-compile, with debug info and so on.

After you change conan settings, the build may failed because can’t find package for specific settings, the conan center repository only provide a few prebuild packages with standard conan settings.

Now, you need find this package’s recipe, build it with your specific settings.

Basic Usage

  1. Download conan-center-index, just git clone it’s github repo
git clone https://github.com/conan-io/conan-center-index.git --depth=1
  1. Select package version, every recipe contains config.yml file, show the available version.
# abseil version
versions:
  "20230802.1":
    folder: all
  "20230125.3":
    folder: all
  "20230125.2":
    folder: all
  "20230125.1":
    folder: all
  "20230125.0":
    folder: all
  "20220623.1":
    folder: all
  "20220623.0":
    folder: all
  "20211102.0":
    folder: all
  1. Create package, we select version 20211102.0 as example
# create abseil for example
cd conan-center-index/recipes/abseil

# conan create all/conanfile.py {NAME}/{VERSION}@{USER}/{CHANNEL} -pr {PROFILE}
conan create all/conanfile.py abseil/20211102.0@thirdparty/stable -pr linux

The NAME, VERSION, USER, CHANNEL are all conan parameters, you can find them in conan docs. PROFILE is also a conan definition, the profile contains a set of conan settings, please ref to conan profile.

  1. Change conan settings and create another package
# change build_type to Debug
conan create all/conanfile.py abseil/20211102.0@thirdparty/stable -pr linux -s build_type=Debug

Cross Compile

If you want to create a package for another platform, such as arm, you can use conan cross compile feature.

Before build, you need create a new profile, specify the cross-compile toolchain, target cpu arch, target os. we create a profile name with aarch64_gcc9.3

toolchain=/opt/aarch64/gcc9.3
target_host=aarch64-linux-gnu
cc_compiler=gcc
cxx_compiler=g++

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CHOST=$target_host
CC=$toolchain/bin/$target_host-$cc_compiler
CXX=$toolchain/bin/$target_host-$cxx_compiler
STRIP=$toolchain/bin/$target_host-strip

[buildenv]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CHOST=$target_host
CC=$toolchain/bin/$target_host-$cc_compiler
CXX=$toolchain/bin/$target_host-$cxx_compiler
STRIP=$toolchain/bin/$target_host-strip

[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=9.3
compiler.libcxx=libstdc++11
build_type=Release

[options]

[build_requires]

You need specify -pr:h and -pr:b, then conan will think you are cross-compiling

conan create all/conanfile.py abseil/20211102.0@thirdparty/stable -pr:b linux -pr:h aarch64_gcc9.3