configure()¶
The configure()
method should be used for the configuration of settings and options in the recipe
for later use in the different methods like generate()
, build()
or package()
. This
method executes while building the dependency graph and expanding the packages dependencies, which means
that when this method executes the dependencies are still not there, they do not exist, and it is not
possible to access self.dependencies
.
For example, for a C (not C++) library, the compiler.libcxx
and compiler.cppstd
settings shouldn’t
even exist during the build()
. It is not only that they are not part of the package_id
, but
they shouldn’t be used in the build process at all. They will be defined in the profile, because
other packages in the graph can be C++ packages and need them, but it is the responsibility of this
recipe to remove them so they are not used in the recipe:
settings = "os", "compiler", "build_type", "arch"
def configure(self):
# Not all compilers have libcxx subsetting, so we use rm_safe
# to avoid exceptions
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
def package_id(self):
# No need to delete those settings here, they were already deleted
pass
For packages where you want to remove every subsetting of a setting, you can use the rm_safe
method
with a wildcard:
settings = "os", "compiler", "build_type", "arch"
def configure(self):
self.settings.rm_safe("compiler.*")
This will remove all the subsettings of the compiler
setting, like compiler.libcxx
or compiler.cppstd
,
but keep the compiler
setting itself (Which self.settings.rm_safe("compiler")
would remove).
Likewise, for a package containing a library, the fPIC
option really only applies when the
library is compiled as a static library, but otherwise, the fPIC
option doesn’t make sense,
so it should be removed:
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
def configure(self):
if self.options.shared:
# fPIC might have been removed in config_options(), so we use rm_safe
self.options.rm_safe("fPIC")
Available automatic implementations¶
Warning
This feature is experimental and subject to breaking changes. See the Conan stability section for more information.
When the configure()
method is not defined, Conan can automatically manage some
conventional options if specified in the
implements ConanFile attribute: