config_options()

The config_options() method is used to configure or constrain the available options in a package before assigning them a value. A typical use case is to remove an option in a given platform. For example, the SSE2 flag doesn’t exist in architectures different than 32 bits, so it should be removed in this method like so:

def config_options(self):
    if self.settings.arch != "x86_64":
        del self.options.with_sse2

The config_options() method executes:

  • Before calling the configure() method.

  • Before assigning the options values.

  • After settings are already defined.

Available automatic implementations

Warning

This feature is experimental and subject to breaking changes. See the Conan stability section for more information.

When the config_options() method is not defined, Conan can automatically manage some conventional options if specified in the implements ConanFile attribute:

auto_shared_fpic

Options automatically managed:

  • fPIC (True, False).

It can be added to the recipe like this:

from conan import ConanFile

class Pkg(ConanFile):
    implements = ["auto_shared_fpic"]
    ...

Then, if no config_options() method is specified in the recipe, Conan will automatically manage the fPIC setting in the config_options step like this:

if conanfile.settings.get_safe("os") == "Windows":
    conanfile.options.rm_safe("fPIC")

Be aware that adding this implementation to the recipe may also affect the configure step.

If you need to implement custom behaviors in your recipes but also need this logic, it must be explicitly declared:

def config_options(self):
    if conanfile.settings.get_safe("os") == "Windows":
        conanfile.options.rm_safe("fPIC")
    if self.settings.arch != "x86_64":
        del self.options.with_sse2