技术标签: 创建conan包-入门指南 创建conan包 conan
本文是基于对conan官方文档Creating packages - Getting started翻译而来, 更详细的信息可以去查阅conan官方文档。
This section introduces how to create your own Conan packages, explain conanfile.py recipes and the commands to build packages from sources in your computer.
本节将介绍如何创建自己的conan软件包,解释 conanfile.py recipes和从计算机源代码构建软件包的命令。
This is a tutorial section. You are encouraged to execute these commands. For this concrete example, you will need CMake installed in your path. It is not strictly required by Conan to create packages, you can use other build systems (as VS, Meson, Autotools and even your own) to do that, without any dependency to CMake.
这是tutorial部分。我们鼓励你执行这些命令。在此具体示例中,您需要在路径中安装 CMake。conan并不严格要求使用 CMake 创建软件包,您可以使用其他构建系统(如 VS、Meson、Autotools 甚至您自己的系统)来创建软件包,而无需依赖 CMake。
Some of the features used in this section are still under development, like CMakeToolchain or cmake_layout(), while they are recommended and usable and we will try not to break them in future releases, some breaking changes might still happen if necessary to prepare for the Conan 2.0 release.
本节中使用的一些功能仍在开发中,如 CMakeToolchain
或 cmake_layout()
,虽然它们是推荐和可用的,而且我们会尽量避免在未来的版本中破坏它们,但如果有必要,为了准备柯南 2.0 的发布,一些破坏性的更改仍可能发生。
Using the conan new command will create a “Hello World” C++ library example project for us:
使用 conan new 命令将为我们创建一个 "Hello World "C++ 库示例项目:
$ mkdir hellopkg && cd hellopkg
$ conan new hello/0.1 --template=cmake_lib
File saved: conanfile.py
File saved: CMakeLists.txt
File saved: src/hello.cpp
File saved: src/hello.h
File saved: test_package/conanfile.py
File saved: test_package/CMakeLists.txt
File saved: test_package/src/example.cpp
The generated files are:
conanfile.py
: 在根文件夹中有一个 conanfile.py,它是主要的recipe文件,负责定义软件包的构建和使用方式。CMakeLists.txt
: 一个简单的通用 CMakeLists.txt,其中没有任何关于柯南的特定内容。src
文件夹:包含简单 C++"hello "库的 src 文件夹。test_package
文件夹:包含一个示例应用程序,该应用程序将需要并链接已创建的软件包。这不是必须的,但对于检查我们是否正确创建了软件包很有用。Let’s have a look at the package recipe conanfile.py:
让我们来看看软件包recipe conanfile.py:
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
class HelloConan(ConanFile):
name = "hello"
version = "0.2"
# Optional metadata
license = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of Hello here>"
topics = ("<Put some tag here>", "<here>", "<and here>")
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False], "fPIC": [True, False]}
default_options = {
"shared": False, "fPIC": True}
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["hello"]
Let’s explain a little bit about this recipe:
让我们来解释一下这个recipe:
exports_sources
属性定义了哪些源会与配方一起导出,这些源会成为软件包配方的一部分(还有其他机制不这样做,稍后解释)。config_options()
方法(与configure()
一起)可以对二进制配置模型进行微调。例如,在 Windows 中没有 fPIC 选项,因此可以将其删除。generate()
方法准备从源代码构建软件包。在本例中,它可以简化为属性 generators = "CMakeToolchain"
,但为了显示这个重要的方法,我们还是把它留了下来。在这种情况下,执行 CMakeToolchain
generate()
方法将创建一个 conan_toolchain.cmake
文件,将 Conan
设置和选项映射为 CMake
语法。build()
方法使用 CMake
封装器调用 CMake
命令。它是一个薄层,在本例中将传递 -DCMAKE_TOOLCHAIN_FILE=<path>/conan_toolchain.cmake
参数,以及其他可能的参数,如 -DCMAKE_BUILD_TYPE=<config>
(如有必要)。它将配置项目并从源代码开始构建。实际使用的参数将从生成的 CMakePresets.json
文件中获取。package()
方法会将构建文件夹中的工件(头文件、库文件)复制到最终的 package
文件夹中。这可以通过简单的 "复制 "命令来完成,但在本例中,它是在利用 CMake
已经存在的安装功能(如果 CMakeLists.txt
没有实现该功能,在此 package()
方法中编写 self.copy()
命令也很容易)。package_info()
方法定义了用户在使用该软件包时必须与 "hello "库链接。还可以定义其他信息,如 include 或 lib 路径。这些信息用于生成器(如 CMakeDeps
)创建的文件,以便用户使用。虽然这种方法可能会与联编系统的输出重复(CMake
可能会生成 xxx-config.cmake
文件),但定义这一点非常重要,因为conan
软件包可以被任何其他联编系统使用,而不仅仅是 CMake
。The contents of the test_package folder is not critical now for understanding how packages are created, the important bits are:
现在,test_package
文件夹的内容对于了解软件包的创建过程并不重要,重要的是这些内容:
test_package
文件夹与单元测试或集成测试不同。这些测试是 "package"测试,用于验证软件包是否已正确创建,以及软件包用户是否能链接并重用软件包。Conan
项目,包含自己的 conanfile.py
、源代码(包括构建脚本),依赖于正在创建的软件包,并构建和执行一个需要软件包中库的小型应用程序。Let’s build the package from sources with the current default configuration (default profile), and then let the test_package folder test the package:
让我们使用当前的默认配置(默认配置文件)从源代码构建软件包,然后让 test_package 文件夹测试软件包:
$ conan create . demo/testing
...
hello/0.1: Hello World Release!
hello/0.1: _M_X64 defined
...
If “Hello world Release!” is displayed, it worked. This is what has happened:
如果显示 “Hello world Release!”,就说明成功了。情况就是这样:
conanfile.py
和 src
文件夹中的内容已被复制(用 Conan
术语来说就是导出)到本地 Conan
缓存中。hello/0.1@demo/testing
软件包,调用 generate()
、build()
和 package()
方法。这将在 Conan
缓存中创建二进制包。conan install
+ conan build
+ test()
方法,检查是否正确创建了软件包。只要在正在处理的 conanfile.py
旁边提供 test_package
文件夹,就会自动执行此操作。We can now validate that the recipe and the package binary are in the cache:
现在我们可以验证缓存中是否有recipe和软件包二进制文件:
$ conan search
Existing package recipes:
hello/0.1@demo/testing
$ conan search hello/0.1@demo/testing
Existing packages for recipe hello/0.1@demo/testing:
Package_ID: 3fb49604f9c2f729b85ba3115852006824e72cab
[options]
shared: False
[settings]
arch: x86_64
build_type: Release
...
The conan create command receives the same command line parameters as conan install so you can pass to it the same settings and options. If we execute the following lines, we will create new package binaries for those configurations:
conan create 命令接收与 conan install 相同的命令行参数,因此可以向其传递相同的设置和选项。如果我们执行以下命令行,就会为这些配置创建新的软件包二进制文件:
$ conan create . demo/testing -s build_type=Debug
...
hello/0.1: Hello World Debug!
$ conan create . demo/testing -o hello:shared=True
...
hello/0.1: Hello World Release!
These new package binaries will be also stored in the Conan cache, ready to be used by any project in this computer, we can see them with:
这些新的软件包二进制文件也将存储在conan缓存中,随时可供这台计算机中的任何项目使用,我们可以通过以下方式查看它们:
$ conan search hello/0.1@demo/testing
Existing packages for recipe hello/0.1@demo/testing:
Package_ID: 127af201a4cdf8111e2e08540525c245c9b3b99e
[options]
shared: True
[settings]
arch: x86_64
build_type: Release
...
Package_ID: 3fb49604f9c2f729b85ba3115852006824e72cab
[options]
shared: False
[settings]
arch: x86_64
build_type: Release
...
Package_ID: d057732059ea44a47760900cb5e4855d2bea8714
[options]
shared: False
[settings]
arch: x86_64
build_type: Debug
...
文章浏览阅读6.6k次,点赞10次,收藏23次。现在开头:Fairseq是一个正在快速迭代的产品,而且是开源的!这不是表扬,这意味着三件事情:1.他没有文档!所有框架代码都没有任何注释,包括函数docstring都没有2.他没有经过有效测试,估计是抢时间吧!即使是官网Readme里的例子也是无法跑起来的!3.他是一个框架,而且是一个非常不Pythonic的框架,充斥着inline/包装器/莫名其妙的语法。虽然这三点决定他真的对不住Facebook的金字招牌,但是作为一个学习者,总要把他运行起来,那么开始这场针对 FaceBOOK派“全_final_lr_scale
文章浏览阅读5.1k次。目录摘要:基本操作与命令介绍:进入top后交互一点点新的操作Author: Keivn.Xu [email protected]摘要: 玩过Linux一定使用过busybox top命令,但下面的操作方法,你不一定有见过。基本操作与命令介绍:console:/ $ busybox top -help top: invalid optio..._busybox top
文章浏览阅读1.6k次。为什么无线信号(RSSI)是负值答:其实归根到底为什么接收的无线信号是负值,这样子是不是容易理解多了。因为无线信号多为mW级别,所以对它进行了极化,转化为dBm而已,不表示信号是负的。1mW就是0dBm,小于1mW就是负数的dBm数。弄清信号强度的定义就行了:RSSI(接收信号强度)Received Signal Strength IndicatorRss=10logP,只需将接受到的信号功率P代..._c#获取低功耗设备的rssi信号强度
文章浏览阅读204次。1.RPC与本地调用的区别RPC远程调用,一般是跨平台、采用http协议,因为http协议底层使用socket技术,只要你的语言支持socket技术,就可以相互进行通讯。比如:java语言开发的接口,使用http协议,如此以来C#语言可以调用。本地调用:只支持java语言与java语言开发,使用虚拟机和虚拟机之间的通讯,RMI。2.雪崩效应产生的原因默认情况下只有一个线程池维护所有的服务接口,如果大量的请求访问同一个接口,达到tomcat线程池默认极限,可能会导致其他服务无法访问。3.雪_接口超时时间过长导致雪崩效应
文章浏览阅读2.7w次,点赞4次,收藏35次。redis常用命令_linux 连接redis
文章浏览阅读3.9k次。2、打开另一台小米手机的小米运动,或者Zepp life,连接手环,打开手环里面的NFC,选择“非加密卡模拟”。3、然后使用小米手环靠近上述步骤1中的小米手机,模拟小米手机的门禁卡。小米手环NFC模拟加密门禁卡会提示“此卡为加密卡,无法模拟”。注意:步骤1中的手机,必须是小米、红米手机,其它安卓手机不行。1、首先找一台带nfc功能的小米手机,模拟加密门禁卡。此时步骤1的小米手机,相当于是未加密的门禁卡)_小米nfc加密卡模拟不了
文章浏览阅读4k次,点赞5次,收藏29次。显著性目标检测常用十种数据集:SOD,提取码:f7uqDUT-OMRON,提取码:wqpnMSRA-B,提取码:rfrbSOC,提取码:d5b9SED2,提取码:q4iaHKU-IS,提取码:2f1iPASCAL-S,提取码:naaxDUTS,提取码:a5w7THUR-15K,提取码:ptk9ECSSD..._sod数据集
文章浏览阅读3.9k次,点赞10次,收藏17次。本文和后续文章将着眼CPU的工作原理阐述伪共享的解决方法和volatile关键字的应用。
文章浏览阅读1.7k次。问题 在线代码编辑器的主要功能是什么? 在学习 GEE 的过程中,我可以去哪里寻求帮助? 如何搜索和导入数据集? 如何创建、共享和保存脚本? 目标 了解代码编辑器中可用的工具 加载图像集合并将其过滤为相关图像 使用几何工具创建研究区域 代码编辑器概述GEE 有一个称为代码编辑器的集成开发环境 (IDE)。代码编辑器有许多功能可以帮助我们在本教程中更轻松地在这种环境中进行编程。有关详尽说明,请参阅GEE 用户指南..._gee怎么新建代码文件
文章浏览阅读6.2k次。在是Eclipse开发的时候,使用Maven打包每次都需要联网下载jar包。第一次需要下载这个可以理解。但是每次都需要下载,就有点问题了...重点是,所用的网络不能访问Maven的私服,所以每次打包都断开网络。这样很麻烦,找资料发现勾选下图中的 Offline(离线) 就可以解决问题了。注意:当你需要下载其他的依赖时,就需要把这个勾去掉,不然连接不上仓库哦。..._maven打包每次都要下载依赖
文章浏览阅读8k次,点赞2次,收藏6次。先看下两个函数的官方解释: pg_cancel_backend() 取消后台操作,回滚未提交事物pg_terminate_backend() 中断session,回滚未提交事物这里和oracle类似kill session的操作是pg_terminate_backend() pg_cancel_backend() 举例:session A:postgres=# create table tb..._pg_cancel_backend pg_ter
文章浏览阅读724次。1_selenium rabbitmq