当前位置: 首页 > article >正文

创建conan包-工具链

创建conan包-工具链

  • 1 Toolchains

本文是基于对conan官方文档Toolchains翻译而来, 更详细的信息可以去查阅conan官方文档。

1 Toolchains

Toolchains are the new way to integrate with build systems in Conan. Recipes can define a generate() method that will return an object which can generate files from the current configuration that can be used by the build systems. Conan generators provide information about dependencies, while toolchains provide a “translation” from the Conan settings and options, and the recipe defined configuration to something that the build system can understand. A recipe that does not have dependencies does not need a generator, but can still use a toolchain.
工具链是conan与构建系统集成的新方法。配方可以定义一个 "generate() "方法,该方法将返回一个对象,该对象可以根据当前配置生成可供构建系统使用的文件。conan生成器提供有关依赖关系的信息,而工具链则将conan设置和选项以及配方定义的配置 "翻译 "为构建系统可以理解的内容。没有依赖关系的配方不需要生成器,但仍可使用工具链。

A toolchain can be defined, among the built-ins toolchains, with an attribute with the name of the toolchain class to use.
在内置工具链中,可以定义一个工具链,其属性包含要使用的工具链类的名称。

generators = "<ToolChainClassName>"

For example, for using the CMake toolchain this should be declared in the recipe:
例如,使用 CMake 工具链时,应在配方中声明这一点:

generators = "CMakeToolchain"

Tip
You can explore available toolchains in the new tools section
您可以在新工具部分查看可用的工具链

But in the more general case, and if it needs any specific configuration beyond the default one:
但在更一般的情况下,如果它需要默认配置之外的任何特定配置:

from conan.tools.cmake import CMakeToolchain

def generate(self):
    tc = CMakeToolchain(self)
    # customize toolchain "tc"
    tc.generate()

It is possible to use the generate() method to create your own files, which will typically be deduced from the current configuration of self.settings and self.options.
你可以使用 generate() 方法创建自己的文件,这些文件通常是根据 self.settingsself.options 的当前配置推导出来的。

from conan.tools.files import save

def generate(self):
    # Based on the self.settings, self.options, the user
    # can generate their own files:
    save("mytoolchain.tool", "my own toolchain contents, deduced from the settings and options")
    # The "mytoolchain.tool" file can be used by the build system to
    # define the build

And as usual, you can create your own toolchain helpers, put them in a python_requires package and reuse them in all your recipes.
像往常一样,你可以创建自己的工具链辅助工具,将其放入 python_requires 包中,并在所有配方中重复使用。

Toolchains have some important advantages:
工具链有一些重要优势:

  • They execute at conan install time. They generate files, not command line arguments, providing better reproducibility and debugging of builds.
  • 它们在conan安装时执行。它们生成的是文件,而不是命令行参数,从而提供更好的可重复性和构建调试。
  • They provide a better developer experience. The command line used by developers locally, like cmake ... will achieve the same build, with the same flags, as the conan build or the build that is done in the cache with a conan create.
  • 它们为开发人员提供了更好的体验。开发人员在本地使用的命令行,如 “cmake …”,将与 "conan build "或在缓存中使用 "conan create "完成的构建一样,具有相同的标记。
  • They are more extensible and configurable.
  • 它们更具扩展性和可配置性。

The toolchains implement most of the build system logic, leaving the build helpers, like CMake(), doing less work, and acting basically as a high level wrapper of the build system. Many of the existing arguments, attributes or methods of those build helpers will not be available. Check the documentation of each toolchain to check the associated build helper available functionality.
工具链实现了大部分的编译系统逻辑,而像 CMake() 这样的编译助手所做的工作较少,它们基本上充当了编译系统的高级封装器。这些联编助手的许多现有参数、属性或方法将不可用。请查阅每个工具链的文档,查看相关联编助手的可用功能。

from conan.tools.cmake import CMakeToolchain, CMake

def generate(self):
    tc = CMakeToolchain(self)
    # customize toolchain "tc"
    tc.generate()

def build(self):
    # NOTE: This is a simplified helper
    # Not all arguments attributes and methods might be available
    cmake = CMake(self)

http://www.kler.cn/a/160415.html

相关文章:

  • MySQL的SQL书写顺序和执行顺序
  • 01:(手撸HAL+CubeMX)时钟篇
  • 【算法一周目】双指针(2)
  • 【操作系统】守护进程
  • 数字孪生在智慧能源项目中的关键作用,你了解多少?
  • 详解基于C#开发Windows API的SendMessage方法的鼠标键盘消息发送
  • Auth的使用、缓存
  • 普中STM32 单片机资料
  • Vue+ElementUI技巧分享:结合Sortablejs实现表格行拖拽
  • 高防CDN技术的崛起与网络安全的演进
  • 多平台展示预约的服装小程序效果如何
  • 探索人工智能领域——每日20个名词详解【day10】
  • 初级数据结构(二)——链表
  • R语言学习
  • SHAP(五):使用 XGBoost 进行人口普查收入分类
  • 打包 抖音直播云游戏
  • 【Delphi】一个函数实现ios,android震动功能 Vibrate(包括3D Touch 中 Peek 震动等)
  • 图像处理中的角点检测Python-OpenCV 中的实现
  • mysql的组合查询
  • 【GAMES101】二维变换和齐次坐标
  • 华为配置风暴控制示例
  • 富时中国A50指数查询方法详解
  • Matlab 曲线动态绘制
  • OpenHarmony北向-让更广泛的应用开发者更容易参与
  • 【南京站-EI会议征稿中】第三届网络安全、人工智能与数字经济国际学术会议(CSAIDE 2024)
  • C/C++---------------LeetCode第2154. 将找到的值乘以 2