1. 安装conan 1.x 并初始化
- 安装python3
python --version # 检查Python版本是否为3.X
# 如果是2.x版本需要安装3.x版本的python
sudo apt install python3.7
# 可以将默认的python映射到python3
sudo gedit ~/.bashrc
alias python='/usr/bin/python3'
- 安装pip,并通过pip安装conan
sudo apt install python3-pip
pip3 install --upgrade setuptools # 缺了这一步很可能conan一直安装报错
pip3 install conan==1.60
conan 1.x版本已经处于deprecated状态,官网已经没有安装包可下载,目前只能通过命令安装。
- 将conan加入环境变量,便于全局访问
export PATH=$PATH:/home/[user]/.local/bin
- 生成profile文件
conan profile update settings.compiler.libcxx=libstdc++11 default
conan profile update settings.compiler.version=7 default
conan profile new default --detect
查看profile的命令是:
conan profile show default
- 添加远程仓库映射
conan remote add smart http://192.168.0.34:8082/artifactory/api/conan/[repo_name]
- 添加访问仓库的用户
conan user -p [password] -r [repo_name] [username]
- 查询远程仓库中的包
conan search poco --remote=conancenter
- 查询本地已经下载的包
conan search "poco*" # 仅仅是简单列出
conan search poco/1.9.4@ #列出包的详细信息
- 下载依赖库
conan install . -if=./build/Debug -s build_type=Debug
2. 创建有源码的包
mkdir [package_name] && cd [package_name] # 创建一个空目录,目录名即为库的包名
conan new [package_name]/1.0.0 --template=cmake_lib # 利用conan创建一个cmake库模板的项目
conan create . [account]/[channel] -s build_type=[Release|Debug] # 创建conan库的包
conan search # 将看到你创建的包在列表中
channel
: [stable|testing|unstable]
随后,可以通过命令conan upload [package_name]/1.0.1@[account]/[channel] --all -r=[repo_name]
上传到jfrog。
3. 创建仅仅已编译好库文件的包
一般来说,我们上传的二进制库可能会有多平台的库文件,建议按arch
和os
分割存放,比如:
├── linux
│ ├── armv8
│ │ ├── include
│ │ └── lib
│ │ └── conanfile.py
│ └── x86_64
│ ├── include
│ └── lib
│ │ └── conanfile.py
├── macos
│ ├── armv8
│ │ ├── include
│ │ └── lib
│ │ └── conanfile.py
│ └── x86_64
│ ├── include
│ └── lib
│ └── conanfile.py
└── windows
├── armv8
│ └── include
│ └── lib
│ └── bin
│ └── conanfile.py
└── x86_64
└── include
└── lib
└── bin
└── conanfile.py
你会发现每个平台的目录下都有一个
conanfile.py
,它们的内容都是一样的,如下:
from conans import ConanFile, tools
class BinaryConan(ConanFile):
name = "smt-logger"
version = "1.0.1"
settings = "os", "compiler", "build_type", "arch"
description = "<Description of SmtLogger here>"
url = "None"
license = "None"
author = "None"
topics = None
def package(self):
self.copy("*")
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
然后,按os
和arch
分别创建对应的包,需要cd到对应目录才能执行下面命令:
conan export-pkg . [package_name]/1.0.1@[account]/[channel] -s os=Linux -s arch=x86_64
conan export-pkg . [package_name]/1.0.1@[account]/[channel] -s os=Linux -s arch=armv8
conan export-pkg . [package_name]/1.0.1@[account]/[channel] -s os=Windows -s arch=x86_64
随后,可以通过命令conan upload [package_name]/1.0.1@[account]/[channel] --all -r=[repo_name]
上传到jfrog。
网友评论