TExcelTAD

Settings vs Options

Conan describes a binary with two kinds of values, and mixing them up is one of the most common beginner mistakes.

Settings Options
Describe the environment: OS, arch, compiler, build type, standard library choices of the package: shared or static, header-only, features
Defined by the global settings.yml (same names for every package) each recipe (options = {...}), so they differ per package
Set in profiles ([settings], -s) recipes' default_options, profiles' [options], -o
Scope usually the whole graph usually one package (by pattern, fmt/*:shared=True)
In package ID yes yes

The rule of thumb: if the value is about the machine and toolchain, it's a setting; if it's about how this library is built, it's an option.

What options does a package have?

The recipe declares them. conan graph info shows the values a binary uses, and the recipe file in the cache shows every allowed value:

bash · try it yourself
conan graph info --requires=fmt/12.1.0 --filter=options 2>&1 | sed -n '/^fmt\/12.1.0/,$p'
echo "--- declared in the recipe"
sed -n '/options = {/,/}/p' "$(conan cache path fmt/12.1.0)/conanfile.py"
fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:
  ref: fmt/12.1.0#6baf0fb8351783472b94ee6e36232391
  options:
    fPIC: True
    header_only: False
    shared: False
    with_fmt_alias: False
    with_os_api: True
    with_unicode: True
--- declared in the recipe
    options = {
        "header_only": [True, False],
        "shared": [True, False],
        "fPIC": [True, False],
        "with_fmt_alias": [True, False],
        "with_os_api": [True, False],
        "with_unicode": [True, False],
    }
    default_options = {
        "header_only": False,
        "shared": False,
        "fPIC": True,
        "with_fmt_alias": False,
        "with_os_api": True,
        "with_unicode": True,
    }

fmt has a header_only option. In header-only mode the library has no compiled code: consumers include the implementation and define FMT_HEADER_ONLY. Let's ask for it.

Changing an option: a different binary

bash · try it yourself
conan install --requires=fmt/12.1.0 -o "fmt/*:header_only=True" -nr 2>&1 | sed -n '/Computing necessary/,$p'
======== Computing necessary packages ========
Requirements
    fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:da39a3ee5e6b4b0d3255bfef95601890afd80709 - Missing
ERROR: Missing binary: fmt/12.1.0:da39a3ee5e6b4b0d3255bfef95601890afd80709

fmt/12.1.0: WARN: Can't find a 'fmt/12.1.0' package binary 'da39a3ee5e6b4b0d3255bfef95601890afd80709' for the configuration:

ERROR: Missing prebuilt package for 'fmt/12.1.0'. You can try:
    - List all available packages using 'conan list "fmt/12.1.0:*" -r=remote'
    - Explain missing binaries: replace 'conan install ...' with 'conan graph explain ...'
    - Try to build locally from sources using the '--build=fmt/12.1.0' argument

More Info at 'https://docs.conan.io/2/knowledge/faq.html#error-missing-prebuilt-package'

That's the missing binary error, and it's honest: our cache only has the static-library build of fmt. Changing an option changed the package ID (da39a3ee… here instead of e029…), and no binary with that ID exists locally. (-nr means "no remote", so Conan doesn't try to reach ConanCenter, which this container can't.) On a machine with network access, ConanCenter usually has prebuilt binaries for popular configurations and Conan would simply download one.

The error suggests the fix: build it from source. Conan downloads the source, so offline that fails too:

bash · try it yourself
conan install --requires=fmt/12.1.0 -o "fmt/*:header_only=True" -nr --build=missing \
  -c tools.files.download:retry=0 2>&1 | grep -E 'Building from source|ERROR' | cut -c1-110
Building from source fmt/12.1.0:da39a3ee5e6b4b0d3255bfef95601890afd80709
ERROR: fmt/12.1.0: Error in source() method, line 86

Two lessons hide in this output. First, --build=missing is how CI usually runs: use binaries where they exist, build the rest. Second, a binary cache is only as good as the configurations you put in it. If your team uses header_only=True, someone has to build and upload that binary to your remote once.

Note: the header-only package ID da39a3ee5e6b4b0d3255bfef95601890afd80709 is the SHA-1 of an empty text. A header-only recipe clears its settings and options in package_id() (headers are the same for every compiler), so every configuration maps to the same, empty, ID.

Changing a setting

A setting change produces the same kind of error; here, a Debug build:

bash · try it yourself
conan install --requires=spdlog/1.17.0 -s build_type=Debug -nr 2>&1 | grep -E 'Main binary|No compatible|- Missing|^ERROR: Missing binary'
fmt/12.1.0: Main binary package 'e0c8523dbb19e11bc26aa5320d1ef4e9a74ec86e' missing
fmt/12.1.0: No compatible configuration found
spdlog/1.17.0: Main binary package 'f5317d8e96ee31caf7c86437afd697cabf2765b7' missing
spdlog/1.17.0: No compatible configuration found
    fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:e0c8523dbb19e11bc26aa5320d1ef4e9a74ec86e - Missing
    spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c:f5317d8e96ee31caf7c86437afd697cabf2765b7 - Missing
ERROR: Missing binary: fmt/12.1.0:e0c8523dbb19e11bc26aa5320d1ef4e9a74ec86e
ERROR: Missing binary: spdlog/1.17.0:f5317d8e96ee31caf7c86437afd697cabf2765b7

For each package Conan first looks for the exact binary, then tries the compatible configurations (other cppstd values) before giving up. Both spdlog and its dependency fmt are missing: -s build_type=Debug applies to every package in the graph, which is exactly what you want for settings (mixing Debug and Release runtime libraries is a classic way to crash on Windows). To change a setting for one package only, use a pattern: -s "fmt/*:build_type=Release".

Where to set options

Where Example When
The recipe's default_options {"shared": False} the package author's default
A consumer's configure() self.options["fmt"].header_only = True your project needs it
[options] in conanfile.txt fmt/*:header_only=True the same, for txt consumers
A profile's [options] *:shared=True a team-wide policy (all shared libraries)
Command line -o "fmt/*:header_only=True" experiments

When two places disagree, the consumer's values win over the dependency's defaults, and the command line wins over profiles.

Test yourself

Is shared=True a setting or an option?

  1. A setting, because it affects linking
  2. An option: it's a choice declared by each recipe
  3. Neither, it's a conf value
  4. It depends on the OS

Why did -o "fmt/*:header_only=True" fail in our container?

  1. fmt has no header_only option
  2. The option changes the package ID, no binary for that ID is cached, and building it needs the source download
  3. Options can't be set on the command line
  4. header_only requires C++20

What does --build=missing do?

  1. Builds every package from source
  2. Builds only the packages whose binary can't be found
  3. Deletes missing packages
  4. Skips missing packages