Requires
The required dependencies should be specified in the [requires] section. Here is an example:
[requires]
mypackage/1.0.0@company/stable
mypackage is the name of the package which is usually the same as the project/library.
1.0.0 is the version which usually matches that of the packaged project/library. This can be any string; it does not have to be a number, so, for example, it could indicate if this is a “develop” or “master” version. Packages can be overwritten, so it is also OK to have packages like “nightly” or “weekly”, that are regenerated periodically.
company is the owner of this package. It is basically a namespace that allows different users to have their own packages for the same library with the same name.
stable is the channel. Channels provide another way to have different variants of packages for the same library and use them interchangeably. They usually denote the maturity of the package as an arbitrary string such as “stable” or “testing”, but they can be used for any purpose such as package revisions (e.g., the library version has not changed, but the package recipe has evolved).
What’s More
- user/channel is optional
If the package was created and uploaded without specifying the user and channel you can omit the user/channel when specifying a reference:
[requires]
packagename/1.2.0
- Overriding requirements
You can specify multiple requirements and override transitive “require’s requirements”. In our example, Conan installed the Poco package and all its requirements transitively:
• openssl/1.0.2t
• zlib/1.2.11
Here is the recipe of the text book Hello World example:
conanfile.txt
[requires]
poco/1.9.4
[generators]
cmake
One can see from the above that all the requirements this example Conan project needs is poco/1.9.4. However, poco/1.9.4 also needs other dependencies. Here one can update some dependency of poco/1.9.4 by add a line in the above [requires] filed, like this:
[requires]
poco/1.9.4
openssl/1.0.2u
The second line will override the openssl/1.0.2t required by POCO with the currently non-existent openssl/1.0.2u. That is, the openssl/1.0.2u added overrides the version that defined in the poco/1.9.4 package.
Another example in which we may want to try some new zlib alpha features: we could replace the zlib requirement with one from another user or channel:
[requires]
poco/1.9.4
openssl/1.0.2u
zlib/1.2.11@otheruser/alpha
Generators
-
“Conan reads the [generators] section from conanfile.txt and creates files for each generator with all the information needed to link your program with the specified requirements. ”
-
“The generated files are usually temporary, created in build folders and not committed to version control, as they have paths to local folders that will not exist in another machine. ”
-
“Moreover, it is very important to highlight that generated files match the given configuration (Debug/Release, x86/x86_64, etc) specified when running conan install. If the configuration changes, the files will change accordingly.”
References
- Conan Documentation --Release 1.58.0