技术标签: 创建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
...
文章浏览阅读4.4w次,点赞11次,收藏56次。分类问题是人类所面临的一个非常重要且具有普遍意义的问题,我们生活中的很多问题归根到底都是分类问题。文本分类就是根据文本内容将其分到合适的类别,它是自然语言处理的一个十分重要的问题。文本分类主要应用于信息检索,机器翻译,自动文摘,信息过滤,邮件分类等任务。文本分类技术发展历史 1960-1970:那时主要通过人工+规则(关键词或者正则表达式)的方式,制定规则的人需要对某类目领域有足够的认知和了解。举_文本特征提取word2vec
文章浏览阅读1k次。本文利用libevent,实现一个C++线程池,,可自定义用户任务类,继承于任务task基类,重写任务基类的纯虚函数实现多态。比如将定义定义处理客户端的请求任务类,实现对客户端请求的并发处理。工作队列:可以理解为线程的队列,一个线程同时可以处理一个任务,空闲的线程回从任务队列取出任务执行。当工作队列空时,线程会睡眠。任务队列:用户将任务加入任务队列,然后通知工作队列,取出一个任务到线程中执行。_windows c++ 开发 客户端 libevent
文章浏览阅读3.4w次,点赞3次,收藏11次。篇一:《工作中存在的不足及改进措施》通过近一段时间的工作,反省自身,还存在许多不足和缺点,现将近期的工作、学习中存在的不足和缺点简要总结如下:1、自身的专业业务水平不高,事故应急处理能力不强.虽然通过学习和工作经验的积累,在业务水平上有了一定的提高,但业务水平和工作经验与其它老同志比还是比较低.在日常工作中偏重于日常生产工作,也忽视了自身思想素质的提高,工作中争强当先的意识不强.2、工作上满足于正..._工作不足之处及改进措施
文章浏览阅读2k次。常用的poi工具,如easy-excel,hutool读取excel是都是先将整个excel加载到内存中分析,然后再一行行遍历,当excel文件太大时读取的时间就会更长,如果我们只需要读取excel的前几行来进行预览就不能使用这种方式,应该按需读取。_java 读取大文件excel
文章浏览阅读237次。HTML_常用标签测试_html标签检测
文章浏览阅读482次。牛顿法是一种用于求解非线性方程组的迭代优化方法。其基本原理是基于泰勒级数展开和一阶导数的近似,通过不断迭代修正初始猜测解来逼近方程组的解。Fx0其中,Fxf1xf2x...fnxT是一个多元函数,xx1x2...xnT是待求解的变量向量。牛顿法的基本思想是,在当前的迭代点xk处,用一个一阶泰勒展开来近似fixfix≈fixkj1∑n∂xj∂fixk。
文章浏览阅读815次。文章目录摘要摘要_后端克里金插值分析
文章浏览阅读3.3w次,点赞10次,收藏36次。我们在 Windows 操作系统中写文档,做笔记,通常使用 Windows 自带的记事本,可是记事本不支持插入图片,创建表格等功能,从而不得不使用 Office Word。不知道大家有没有这样的感觉,使用 Office Word 写文档,效率极低,需要一边敲字,一边使用鼠标排版,比如:在文章中给团队的名字“LSGO软件技术团队”加粗,就需要先用鼠标选中这个词语,然后点击工具栏中“B”形状的工具..._有道云笔记如何建立 文档索引
文章浏览阅读137次。IP-guard 远程命令执行漏洞_ipg 漏洞
文章浏览阅读255次。2017年,全球数据泄露事件已不仅是呈翻倍的速度增长。16年的14亿条,到17年仅上半年的17亿条,这样的数据泄露规模你是否还在存在侥幸心理,就是那所谓的“怎么可能刚好落在我身上”。随着我们在工作、生活中的云化,就在今天,万物互联已经融入到我们每个人的生活中,相信在不就的将来,整个IOT时代也将会很快的到来。仔细回忆一下,今天我们所做的任何情都离不..._8,iot时代,数据安全有哪些新特征?
文章浏览阅读6.7k次,点赞47次,收藏143次。存放文本时,也可以使用Text数据类型,可以将TEXT列视为VARCHAR列,注意Text不能有默认值,大小0-2^16字节;同一查询在同一事务中多次进行,由于其它提交事务所做的修改和删除,每次返回不同的结果集,则发生不可重复读;多个连接开启各自事务操作数据库中数据时,数据库系统要负责隔离操作,以保证各个连接在获取数据是的准确性;同一查询在同一个事务中多次执行,由于其它提交事务所做的插入操作,每次返回不同的结果集,此时发生幻读;同真是的表一样,视图包含列,其数据来自对应的真实表(基表)_mysql教程
文章浏览阅读550次,点赞10次,收藏6次。GD32官方的开发环境(基于Eclipse)的使用。_gd32e23 开发环境