技术标签: 创建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
...
文章浏览阅读3.5k次,点赞2次,收藏13次。为了从FTP服务器下载文件,需要要实现一个简单的FTP客户端。FTP(文件传输协议) 是 TCP/IP 协议组中的应用层协议。FTP协议使用字符串格式命令字,每条命令都是一行字符串,以“\r\n”结尾。客户端发送格式是:命令+空格+参数+"\r\n"的格式服务器返回格式是以:状态码+空格+提示字符串+"\r\n"的格式,代码只要解析状态码就可以了。读写文件需要登陆服务器,特殊用..._ftp 登录返回230
文章浏览阅读648次。前提:systemctl stop firewalld 关闭防火墙关闭selinux查看getenforce临时关闭setenforce 0永久关闭sed-i'/SELINUX/s/enforcing/disabled/'/etc/selinux/configselinux的三种模式enforcing:强制模式,SELinux 运作中,且已经正确的开始限制..._centos7 安装rabbitmq3.6.5
文章浏览阅读5.8k次。满意答案s55f2avsx2017.09.05采纳率:46%等级:12已帮助:5646人新版Android Studio/IntelliJ IDEA可以直接导入eclipse项目,不再推荐使用eclipse导出gradle的方式2启动Android Studio/IntelliJ IDEA,选择 import project3选择eclipse 项目4选择 create project f..._android studio 项目导入idea 看不懂安卓项目
文章浏览阅读860次,点赞2次,收藏6次。AI大模型技术已经在自然语言处理、计算机视觉、多模态交互等领域取得了显著的进展和成果,同时也引发了一系列新的挑战和问题,如数据质量、计算效率、知识可解释性、安全可靠性等。城市运维涉及到多个方面,如交通管理、环境监测、公共安全、社会治理等,它们需要处理和分析大量的多模态数据,如图像、视频、语音、文本等,并根据不同的场景和需求,提供合适的决策和响应。知识搜索有多种形式,如语义搜索、对话搜索、图像搜索、视频搜索等,它们可以根据用户的输入和意图,从海量的数据源中检索出最相关的信息,并以友好的方式呈现给用户。_ai大模型应用开发
文章浏览阅读8.2k次,点赞12次,收藏121次。为什么要测量阻抗呢?阻抗能代表什么?阻抗测量的注意事项... ...很多人可能会带着一系列的问题来阅读本文。不管是数字电路工程师还是射频工程师,都在关注各类器件的阻抗,本文非常值得一读。全文13000多字,认真读完大概需要2小时。一、阻抗测试基本概念阻抗定义:阻抗是元器件或电路对周期的交流信号的总的反作用。AC 交流测试信号 (幅度和频率)。包括实部和虚部。图1 阻抗的定义阻抗是评测电路、元件以及制作元件材料的重要参数。那么什么是阻抗呢?让我们先来看一下阻抗的定义。首先阻抗是一个矢量。通常,阻抗是_阻抗实部和虚部
文章浏览阅读955次。前面章节分享试用了pyzero,pygame但随着想增加更丰富的游戏内容,好多还要进行自己编写类,从今天开始解绍一个新的python游戏库arcade模块。通过此次的《连连看》游戏实现,让我对swing的相关知识有了进一步的了解,对java这门语言也有了比以前更深刻的认识。java的一些基本语法,比如数据类型、运算符、程序流程控制和数组等,理解更加透彻。java最核心的核心就是面向对象思想,对于这一个概念,终于悟到了一些。_arcade语言 like
文章浏览阅读1.1k次。源码简介与安装说明:2021增强版短视频去水印源码 去水印微信小程序源码网站 去水印软件源码安装环境(需要材料):备案域名–服务器安装宝塔-安装 Nginx 或者 Apachephp5.6 以上-安装 sg11 插件小程序已自带解析接口,支持全网主流短视频平台,搭建好了就能用注:接口是公益的,那么多人用解析慢是肯定的,前段和后端源码已经打包,上传服务器之后在配置文件修改数据库密码。然后输入自己的域名,进入后台,创建小程序,输入自己的小程序配置即可安装说明:上传源码,修改data/_去水印机要增强版
文章浏览阅读557次。1. 触发器是FPGA存储数据的基本单元2. 触发器作为时序逻辑的基本元件,官方提供了丰富的配置方式,以适应各种可能的应用场景。_fdre #(.init(1'b0) // initial value of register (1'b0 or 1'b1) ) fdce_osc (
文章浏览阅读560次。本该是不同编译器结果不同,但是尝试了g++ msvc都是先计算c,再计算b,最后得到a+b+c是经过赋值以后的b和c参与计算而不是6。由上表可知,将q复制到p数组可以表示为:*p++=*q++,*优先级高,先取到对应q数组的值,然后两个++都是在后面,该行运算完后执行++。在电脑端编译完后会分为text data bss三种,其中text为可执行程序,data为初始化过的ro+rw变量,bss为未初始化或初始化为0变量。_嵌入式面试笔试c语言知识点
文章浏览阅读2.3k次。57 Things I've Learned Founding 3 Tech CompaniesJason Goldberg, Betashop | Oct. 29, 2010, 1:29 PMI’ve been founding andhelping run techn_mature
文章浏览阅读1.9k次。问题:先讲下需求,有若干个文本文件(txt或者csv文件等),每行代表一条数据,现在希望能合并成 1 个文本文件,且需要去除重复行。分析:一向奉行简单原则,如无必要,绝不复杂。如果数据量不大,那么如下两条命令就可以搞定合并:cat a.txt >> new.txtcat b.txt >> new.txt……去重:cat new...._python 超大文本合并
文章浏览阅读489次。这个过渡页是第一次打开小程序展示的,点击某个小程序前把手机的开发者->network link conditioner->enable & very bad network 就会在停在此页。比如《支付宝运动》这个小程序先看这个类的.h可以看到它继承于DTViewController点击左上角返回的方法- (void)back;#import "DTViewController.h"#import "APBaseLoadingV..._类似支付宝页面过度加载页