Profiles & conf
A profile is a text file that describes a configuration: which OS, architecture, compiler, standard library, C++ standard and build type you're building for, plus options, configuration values and environment variables. Every Conan command reads two of them: the host profile (where the binaries will run) and the build profile (where the build runs). Without arguments, both are default.
Anatomy of a profile
include(default)
[settings]
build_type=Debug
compiler.cppstd=20
[options]
spdlog/*:header_only=True
[conf]
tools.build:jobs=8
tools.cmake.cmaketoolchain:generator=Ninja
[buildenv]
CC=gcc-13
CXX=g++-13
[tool_requires]
cmake/4.4.4| Section | Purpose |
|---|---|
include(...) |
start from another profile and override parts of it |
[settings] |
the binary configuration; changes the package ID |
[options] |
option values for packages, by pattern |
[conf] |
tool configuration (tools.*, core.*, user.*): job counts, generators, compiler executables, flags. Not part of the package ID by default |
[buildenv] / [runenv] |
environment variables for the build or for running |
[tool_requires] |
build tools injected into every package, e.g. a pinned CMake |
[platform_requires] |
packages the system already provides; Conan won't install them |
Profiles can also be Jinja2 templates ({{ os.getenv("CC") }}, {% if ... %}), and can set values per package: zlib/*:build_type=Release keeps one dependency in Release inside a Debug build.
Writing and checking a custom profile
Profiles live in ~/.conan2/profiles/ (use them by name) or anywhere on disk (use them by path, which is handy for profiles committed to your repository). conan profile show prints the result after includes and overrides:
cat > ~/.conan2/profiles/cpp20-ninja <<'P'
include(default)
[settings]
compiler.cppstd=20
[conf]
tools.build:jobs=1
tools.cmake.cmaketoolchain:generator=Ninja
P
conan profile list
conan profile show -pr:h cpp20-ninja 2>&1 | sed -n '/Host profile/,/^$/p'Profiles found in the cache:
cpp20-ninja
default
Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=20
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
[conf]
tools.build:jobs=1
tools.cmake.cmaketoolchain:generator=Ninja
Notice that -pr:h only changed the host profile; the build profile stays default. -pr (without :h) sets both.
Using it
Our cache only has binaries built with gnu17. A C++20 consumer still works (-nr, short for --no-remote, keeps Conan from asking ConanCenter first, which this offline container can't reach): Conan's built-in compatibility plugin knows that a library compiled with another C++ standard can usually be linked into a C++20 program, so it tries the other cppstd values and accepts the gnu17 binary:
cat > ~/.conan2/profiles/cpp20-ninja <<'P'
include(default)
[settings]
compiler.cppstd=20
[conf]
tools.build:jobs=1
tools.cmake.cmaketoolchain:generator=Ninja
P
mkdir -p app && cd app
cat > conanfile.txt <<'TXT'
[requires]
fmt/12.1.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
TXT
cat > CMakeLists.txt <<'TXT'
cmake_minimum_required(VERSION 3.25)
project(app CXX)
find_package(fmt REQUIRED CONFIG)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE fmt::fmt)
TXT
cat > main.cpp <<'SRC'
#include <fmt/core.h>
#include <span>
int main() {
int data[] = {3, 1, 4};
std::span<int> s(data); // C++20
fmt::print("__cplusplus = {}, span size = {}\n", __cplusplus, s.size());
}
SRC
conan install . -pr cpp20-ninja -nr 2>&1 | sed -n '/Computing necessary/,/^$/p'
cmake --preset conan-release | grep 'C++ Standard'
cmake --build --preset conan-release > /dev/null
./build/Release/app======== Computing necessary packages ========
fmt/12.1.0: Main binary package 'a2f52d8a843d621154aa73b66f1bc47a52420135' missing
fmt/12.1.0: Checking 9 compatible configurations
fmt/12.1.0: Found compatible package 'e02956bd268869d4519cb2b90dc7b4e51911a5d0': compiler.cppstd=gnu17
Requirements
fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:e02956bd268869d4519cb2b90dc7b4e51911a5d0#a857dc2fda2e0c13d61393798f6a9684 - Cache
-- Conan toolchain: C++ Standard 20 with extensions OFF
__cplusplus = 202002, span size = 3
Host and build profiles: cross-compiling
The two-profile model is what makes cross-compiling work. Building on an x86-64 Linux machine for a 64-bit ARM board, you'd write a host profile for the board and keep default as the build profile:
# profiles/rpi-armv8
[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=13
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Release
[buildenv]
CC=aarch64-linux-gnu-gcc-13
CXX=aarch64-linux-gnu-g++-13conan install . -pr:h ./profiles/rpi-armv8 -pr:b default --build=missingLibraries (requires) are resolved for the host profile; build tools (tool_requires such as cmake or protobuf's protoc) for the build profile, because they have to run on your machine. The cross toolchain itself isn't in our container, so this one is a sample.
conf: configuring the tools
[conf] values change how tools behave without changing which binary is used. A few you'll see often:
| conf | Effect |
|---|---|
tools.build:jobs |
parallel jobs for builds Conan runs and for presets |
tools.cmake.cmaketoolchain:generator |
CMake generator for the presets |
tools.build:compiler_executables |
{"c": "clang-18", "cpp": "clang++-18"} |
tools.build:cxxflags / cflags / sharedlinkflags |
extra flags (prefer settings when one exists) |
tools.system.package_manager:mode |
let Conan run apt/dnf for system requirements (check, install) |
core:non_interactive |
never prompt (CI) |
core.sources:download_cache |
a shared download cache folder |
Put team-wide values in profiles, machine-wide values in global.conf, and one-off overrides on the command line with -c.
Test yourself
What is the difference between -pr:h and -pr:b?
- Header vs binary profiles
- Host profile (where binaries run) vs build profile (where the build runs)
- Home vs base profile
- There is none
The profile asked for compiler.cppstd=20, but only a gnu17 fmt binary exists. Why did the install succeed?
- Conan rebuilt fmt
- The compatibility plugin tried other cppstd values and accepted the gnu17 binary
- cppstd is ignored
- It downloaded a C++20 binary
Which profile section does NOT change package IDs by default?
- [settings]
- [options]
- [conf]
- None of them