本文主要是介绍conan入门(三十一):在命令行(shell)中从profile中读取配置参数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近使用conan来执行本地或交叉编译时,我发现我需要知道当前profile定义的编译器的类型和版本以及平台,希望用profile中定义的os,arch,compier生成安装路径名如windows-msvc-x86_64
,该怎么实现呢?
conan profile show
基本的思路就是用 conan profile show
命令获取profile中的配置参数,(参见 https://docs.conan.io/2/reference/commands/profile.html,
执行 conan profile show --format=json
可以以json 格式输出当前profile(host及build)中定义所有的参数
如下:
{"host": {"settings": {"arch": "x86_64","build_type": "Release","compiler": "gcc","compiler.cppstd": "gnu11","compiler.libcxx": "libstdc++11","compiler.version": "5.2","os": "Windows"},"package_settings": {},"options": {"boost/*:without_stacktrace": "True"},"tool_requires": {},"conf": {},"build_env": ""},"build": {"settings": {"arch": "x86_64","build_type": "Release","compiler": "gcc","compiler.cppstd": "gnu11","compiler.libcxx": "libstdc++11","compiler.version": "5.2","os": "Windows"},"package_settings": {},"options": {"boost/*:without_stacktrace": "True"},"tool_requires": {},"conf": {},"build_env": ""}
}
有了这个json,就可以用python的json工具来读取其中的内容了
示例一
如下命令读取host profile的编译类型字段(host.settings.compiler)
conan profile show --format=json | python -c "import sys, json; print(json.load(sys.stdin)['host']['settings']['compiler'])"
输出
gcc
示例二
如下读取compiler,arch,os字段拼写生成完整的类machine描述
conan profile show --format=json | python -c "import sys, json; j=json.load(sys.stdin)['host']['settings'];m=j['os']+'-'+j['compiler']+'-'+j['arch']; print(m.lower())"
输出
windows-gcc-x86_64
参考资料
《profile》
《Parse JSON using Python?》
这篇关于conan入门(三十一):在命令行(shell)中从profile中读取配置参数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!