Build policies
By default, conan install command will search for a binary package (corresponding to our settings and defined options) in a remote. If it’s not present the install command will fail.
As previously demonstrated, we can use the --build option to change the default conan install behavior:
--build some_package will build only “some_package”.
--build missing will build only the missing requires.
--build will build all requirements from sources.
--build outdated will try to build from code if the binary is not built with the current recipe or when missing binary package.
--build pattern* will build only the packages with the reference starting with “pattern”.
With the build_policy
attribute the package creator can change the default Conan’s build behavior. The allowed build_policy values are:
missing
: If no binary package is found, Conan will build it without the need to invoke Conan install with --build missing option.always
: The package will be built always, retrieving each time the source code executing the “source” method.
class PocoTimerConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "Poco/1.7.8p3@pocoproject/stable" # comma-separated list of requirements
generators = "cmake", "gcc", "txt"
default_options = {"Poco:shared": True, "OpenSSL:shared": True}
build_policy = "always" # "missing"
These build policies are especially useful if the package creator doesn’t want to provide binary package; for example, with header only libraries.
The always
policy will retrieve the sources each time the package is installed, so it can be useful for providing a “latest” mechanism
or ignoring the uploaded binary packages.
The package pattern can be referred as a case-sensitive fnmatch pattern of the package name or the full package reference. e.g --build Poco, --build Poc*, --build zlib/*@conan/*, --build *@conan/stable or --build zlib/1.2.11@conan/stable.