“conanfile.txt“: the recipe

本文介绍了Conan包管理器如何在`[requires]`和`[generators]`部分指定依赖项,包括不同版本、渠道的使用,以及如何通过`generators`生成配置文件。还讨论了如何覆盖包的transitiverequirements和管理临时生成文件以适应不同的配置。
摘要由CSDN通过智能技术生成

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

  1. 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
  1. 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

  1. “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. ”

  2. “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. ”

  3. “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

  1. Conan Documentation --Release 1.58.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值