技术标签: 创建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
...
文章浏览阅读5.4k次,点赞4次,收藏13次。#include <stdio.h>#include <unistd.h>#include <termios.h> static struct termios initial_settings, new_settings;static int peek_character = -1;void init_keyboard(void);void clo..._linux/input.h 键盘编号
文章浏览阅读69次。文章目录1SaltStack数据系统2 SaltStack数据系统组件2.1 SaltStack组件之Grains2.2 SaltStack组件之Pillar2.3 Grains与Pillar的区别1SaltStack数据系统SaltStack有两大数据系统,分别是GrainsPillar2 SaltStack数据系统组件2.1 SaltStack组件之GrainsGrains是SaltStack的一个组件,其存放着minion启动时收集到的信息。Grains是SaltStack组件中非_comment: no top file or master_tops data matches found. please see master lo
文章浏览阅读3.4k次,点赞6次,收藏3次。当出现这个错误提示的时候,很有可能代码并没有问题,而是编译器的设定问题。测试代码如下:#include using namespace std;//函数模板templatevoid swap(T &a,T &b){ T temp; temp = a; a = b; b = temp;}int main(int ,char **){ int a = 1, b _swap对重载函数的调用不明确
文章浏览阅读1w次,点赞8次,收藏120次。ZYNQ PCIe-DMA源码 例程 PS-PL交互 linux/裸机 verilog C/C++ZYNQ PCIe-DMA的实现过程一、概述二、基础知识三、系统总框架四、工作原理与工作模式五、接口时序六、资源使用情况七、PS-PL交互以及测试程序ZYNQ PCIe-DMA的实现过程近期在网上淘来个源码,看了之后觉得还不错。完全刷新我对ZYNQ的认知啊,原来ZYNQ也可以这么玩的。PS-PL交..._c++ 往pcie发送数据
文章浏览阅读173次。该项目含有源码、文档、程序数据库、配套开发软件、软件安装教程项目运行环境配置:Pychram社区版py项目技术:django + python+ Vue 等等组成,B/S模式 +pychram管理等等。环境需要1.运行环境:最好是python3.7.7,我们在这个版本上开发的。其他版本理论上也可以。2.pycharm环境:pycharm都可以。推荐pycharm社区版;3.mysql环境:建议是用5.7版本均可。_用python设计一个宿舍管理系统,要求能实现寝室信息的增加、删除、修改、查询以及
文章浏览阅读8.4k次,点赞5次,收藏41次。一、安装Apache$ sudo apt-get install apache2二、修改服务器访问端口Apache2的默认访问端口为80,可修改为其他端口(当端口被占用时需要更改其访问端口)进入apache2的安装目录 /etc/apache2/,修改ports.conf文件$ cd /etc/apache2/$ sudo chmod 775 ports.conf$ vim po..._linux怎么搭http apache服务器
文章浏览阅读579次。从DOM(文本对象模型来看)DOM将文档中的节点看作是一个个的对象,包括文档节点(document),元素节点(标签名),属性节点(不是元素节点的子节点)、文本节点,注释节点,上面谈到的每个节点都是一个对象,其中元素节点包括但不限于html、head、body,浏览器为我们创建了访问文档中的节点的入口,也就是document对象,其中document对象也是window对象的属性,document对象是包括html对象的我们所说的网页,一般由三种组成HTML(结构)、CSS(表现)、Js(形式,实现交_body、html、视口三合一
文章浏览阅读149次。摘要:据《科创板日报》7 月 4 日报道,有消息称,Meta 将重返中国,已经与多家中国科技公司进行了讨论,目前可能会和腾讯进行合作,后者或成为 Meta Quest 系列头显的独家经销商,且将为 Quest 头显开发 VR 游戏。对此,腾讯回应表示,不予置评。图片来源:由无界AI生成热点资讯腾讯将发布面向大模型训练的自研向量数据库据《科创板日报》7 月 4 日报道,腾讯云将在今日下午正式发布自研...
文章浏览阅读151次。0 说明{ 手册制作: 雪松 更新日期: 2015-05-13 欢迎系统运维加入Q群: 198173206 # 加群请回答问题 欢迎运维开发加入Q群: 365534424 # 不定期技术分享 请使用"notepad++"或其它编辑器打开此文档, "alt+0"将函数折叠后方便查阅 请勿删除信息, 转载请说明出处, 抵制不道德行..._gawk '{ sum += $2 }; end { print sum }' /
文章浏览阅读610次。https://stackoverflow.com/questions/75103127/getting-notimplementederror-could-not-run-torchvisionnms-with-arguments-fr_could not run torchvision::nms
文章浏览阅读399次。其中最重要的是头盔中两个屏幕,用的是比较高端的三星AMOLED屏幕,屏幕尺寸对角线为91.8mm,PPI(每英寸集成的像素)达到了447(像素密度越高表现出来的画面就更细腻)。体验者可以在一个小范围的空间中行走,体验制作好的内容。是通过摄像头不停的采集周围环境的图像来达到设备的姿态估计(比如噪音等一些没用的信息也会影响到它的准确性)。是通过计算机视觉,以及设备自身自带的传感器比如陀螺仪、加速器来实现位置的追踪。不需要外部硬件来定位。由LED阵列和横向纵向的两个马达,马达以非常高的频率扫描场景中的定位。_htc是什么硬件
文章浏览阅读1.7k次,点赞25次,收藏29次。而在机动车的自动识别过程中,通过利用深度学习的算法来让计算机通过不断地获取信息要素形成信息库,可以更好的提升计算机对于车辆的识别能力。本次就是通过利用了深度学习技术结合Python开发工具来设计一款能够在线通过图片分析来识别车辆的品牌的软件。_pycharm实时检测车辆及源码