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

使用conan包 - 工作流程

使用conan包 - 工作流程

  • 主目录 conan Using packages
  • 1 Single configuration
  • 2 Multi configuration

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

This section shows how to setup your project and manage dependencies (i.e., install existing packages) with Conan.
本节将介绍如何使用 Conan 设置项目和管理依赖关系(即安装现有软件包)。

主目录 conan Using packages

  • Installing dependencies
    • Requires
    • Generators
    • Options
  • Using profiles
  • Workflows
    • Single configuration
    • Multi configuration
  • Debugging packages

This section summarizes some possible layouts and workflows when using Conan together with other tools as an end-user for installing and consuming existing packages. To create your own packages, please refer to Creating Packages.
本节总结了作为最终用户使用 Conan 和其他工具安装和使用现有软件包时的一些可能布局和工作流程。要创建自己的软件包,请参阅 “Creating Packages”。

Whether you are working on a single configuration or a multi configuration project, in both cases, the recommended approach is to have a conanfile (either .py or .txt) at the root of your project.
无论是单配置项目还是多配置项目,推荐的做法都是在项目根目录下建立一个 conanfile(.py 或 .txt)

1 Single configuration

When working with a single configuration, your conanfile will be quite simple as shown in the examples and tutorials we have used so far in this user guide. For example, in Getting started, we showed how you can run the conan install … command inside the build folder resulting in the conaninfo.txt and conanbuildinfo.cmake files being generated there too. Note that the build folder is temporary, so you should exclude it from version control to exclude these temporary files.
在使用单一配置时,您的 conanfile 将非常简单,正如本用户指南中的示例和教程所示。例如,在 "Getting started"中,我们展示了如何在构建文件夹中运行 conan install …命令,从而在该文件夹中生成 conaninfo.txt 和 conanbuildinfo.cmake 文件。请注意,联编文件夹是临时文件,因此应将其从版本控制中排除,以排除这些临时文件。

Out-of-source builds are also supported. Let’s look at a simple example:
还支持源外构建。让我们来看一个简单的例子:

$ git clone https://github.com/conan-io/examples.git
$ cd libraries/poco
$ conan install ./md5 --install-folder=md5_build

This will result in the following layout:
这将产生以下布局:

md5_buildconaninfo.txtconanbuildinfo.txtconanbuildinfo.cmake
md5CMakeLists.txt  # If using cmake, but can be Makefile, sln...README.mdconanfile.txtmd5.cpp

Now you are ready to build:
现在您已准备好构建了:

$ cd md5_build
$ cmake ../md5 -G "Visual Studio 15 Win64"  # or other generator
$ cmake --build . --config Release
$ ./bin/md5
> c3fcd3d76192e4007dfb496cca67e13b

We have created a separate build configuration of the project without affecting the original source directory in any way. The benefit is that we can freely experiment with the configuration: We can clear the build folder and build another. For example, changing the build type to Debug:
我们为项目创建了一个独立的构建配置,但丝毫不影响原始源代码目录。这样做的好处是,我们可以自由地对配置进行实验: 我们可以清除构建文件夹,然后构建另一个文件夹。例如,将构建类型更改为调试:

$ rm -rf *
$ conan install ../md5 -s build_type=Debug
$ cmake ../md5 -G "Visual Studio 15 Win64"
$ cmake --build . --config Debug
$ ./bin/md5
> c3fcd3d76192e4007dfb496cca67e13b

2 Multi configuration

You can also manage different configurations, whether in-source or out of source, and switch between them without having to re-issue the conan install command (Note however, that even if you did have to run conan install again, since subsequent runs use the same parameters, they would be very fast since packages would already have been installed in the local cache rather than in the project)
您还可以管理不同的配置(无论是源内配置还是源外配置),并在它们之间切换,而无需重新发布 conan install 命令(请注意,即使您必须再次运行 conan install,由于后续运行使用相同的参数,它们也会非常快,因为软件包已经安装在本地缓存中,而不是项目中。

$ git clone git@github.com:conan-io/examples
$ cd libraries/poco
$ conan install md5 -s build_type=Debug -if md5_build_debug
$ conan install md5 -s build_type=Release -if md5_build_release$ cd md5_build_debug && cmake ../md5 -G "Visual Studio 15 Win64" && cd ../..
$ cd md5_build_release && cmake ../md5 -G "Visual Studio 15 Win64" && cd ../..

Note
You can either use the --install-folder or -if flags to specify where to generate the output files, or manually create the output directory and navigate to it before executing the conan install command.
您可以使用 --install-folder-if 标志指定生成输出文件的位置,或者在执行 conan install 命令前手动创建输出目录并导航到该目录。

So the layout will be:
因此,布局将会是:

md5_build_debugconaninfo.txtconanbuildinfo.txtconanbuildinfo.cmakeCMakeCache.txt # and other cmake files
md5_build_releaseconaninfo.txtconanbuildinfo.txtconanbuildinfo.cmakeCMakeCache.txt # and other cmake files
example-poco-timerCMakeLists.txt  # If using cmake, but can be Makefile, sln...README.mdconanfile.txtmd5.cpp

Now you can switch between your build configurations in exactly the same way you do for CMake or other build systems, by moving to the folder in which the build configuration is located, because the Conan configuration files for that build configuration will also be there.
现在,您可以用与 CMake 或其他构建系统完全相同的方式在构建配置之间切换,只需移动到构建配置所在的文件夹即可,因为该构建配置的 Conan 配置文件也在该文件夹中。

$ cd md5_build_debug && cmake --build . --config Debug && cd ../..
$ cd md5_build_release && cmake --build . --config Release && cd ../..

Note that the CMake include() of your project must be prefixed with the current cmake binary directory, otherwise it will not find the necessary file:
请注意,您项目的 CMake include() 必须以当前 cmake 二进制目录为前缀,否则它将找不到所需的文件:

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

See also
There are two generators, cmake_multi and visual_studio_multi that could help to avoid the context switch and using Debug and Release configurations simultaneously. Read more about them in cmake_multi and visual_studio_multi
cmake_multivisual_studio_multi 这两个生成器可以帮助避免上下文切换,并同时使用Debug和Release配置。在 cmake_multi 和 visual_studio_multi 中了解更多。

http://www.lryc.cn/news/246079.html

相关文章:

  • 【LeeCode】59.螺旋矩阵II
  • rsyslog学习
  • Navicat 技术指引 | GaussDB服务器对象的创建/设计(编辑)
  • 有哪些可信的SSL证书颁发机构?
  • MidJourney笔记(4)-settings
  • 前端开发学习 (三) 列表功能
  • win11渗透武器库,囊括所有渗透工具
  • 13-21-普通数组、矩阵
  • 代码随想录算法训练营第四十六天【动态规划part08】 | 139.单词拆分、背包总结
  • go语言基础 break和contine区别
  • vue3父子组件通过$parent与ref通信
  • PHP中的常见的超全局变量
  • leetcode9.回文数
  • springboot(ssm大学生二手电子产品交易平台 跳蚤市场系统Java(codeLW)
  • 关于微信小程序中如何实现数据可视化-echarts动态渲染
  • 在Windows WSL (Linux的Windows子系统)上运行的Ubuntu如何更改主机名
  • 如何使用内网穿透将Tomcat网页发布到公共互联网上【内网穿透】
  • 网络入门---网络的大致了解
  • 构建沉浸式 AI 文本编辑器:开源 3B 编辑器的设计原则与思路
  • 【从删库到跑路 | MySQL总结篇】表的增删查改(进阶上)
  • [每周一更]-(第74期):Docker-compose 部署Jenkins容器-英文版及错误纠错
  • MySQL日期函数sysdate()与now()的区别,获取当前时间,日期相关函数
  • 邦芒解析:面试怎么谈自身优缺点
  • 【libGDX】加载G3DJ模型
  • 0基础学习VR全景平台篇第123篇:VR视频航拍补天 - PR软件教程
  • webpack打包三方库直接在html里面使用
  • Redis使用increment方法返回null的原因以及解决方案
  • springMVC,什么是Spring MVC? Spring MVC的主要组件? springMVC工作原理/流程 MVC框架
  • 【论文阅读】TACAN:控制器局域网中通过隐蔽通道的发送器认证
  • C语言第三十五弹---打印九九乘法表