使用conan包 - 使用配置文件

使用conan包 - 使用配置文件

  • 主目录 conan Using packages
  • Using profiles

本文是基于对conan官方文档Using profiles的翻译而来, 更详细的信息可以去查阅conan官方文档。

This section shows how to setup your project and manage dependencies (i.e., install existing packages) with Conan.
本节将介绍如何使用 Conan 设置项目和管理依赖关系(即安装现有软件包)。

主目录 conan Using packages

  • Installing dependencies
    • Requires
    • Generators
    • Options
  • Using profiles
  • Workflows
    • Single configuration
    • Multi configuration
  • Debugging packages

Using profiles

So far, we have used the default settings stored in ~/.conan/profiles/default and defined custom values for some of them as command line arguments.
到目前为止,我们使用了 ~/.conan/profiles/default 中存储的默认设置,并将其中一些设置的自定义值定义为命令行参数。

However, in large projects, configurations can get complex, settings can be very different, and we need an easy way to switch between different configurations with different settings, options etc. An easy way to switch between configurations is by using profiles.
然而,在大型项目中,配置可能会变得复杂,设置可能会大相径庭,我们需要一种简便的方法来在具有不同设置、选项等的不同配置之间进行切换。在不同配置间切换的简便方法就是使用配置文件。

A profile file contains a predefined set of settings, options, environment variables, and tool_requires specified in the following structure:
配置文件包含一组预定义的设置、选项、环境变量和工具要求,具体结构如下:

[settings]
setting=value

[options]
MyLib:shared=True

[env]
env_var=value

[tool_requires]
tool1/0.1@user/channel
tool2/0.1@user/channel, tool3/0.1@user/channel
*: tool4/0.1@user/channel

Options allow the use of wildcards letting you apply the same option value to many packages. For example:
选项允许使用通配符,这样就可以将相同的选项值应用于多个软件包。例如

[options]
*:shared=True

Here is an example of a configuration that a profile file may contain:
下面是配置文件可能包含的配置示例:

clang_3.5

 [settings]
 os=Macos
 arch=x86_64
 compiler=clang
 compiler.version=3.5
 compiler.libcxx=libstdc++11
 build_type=Release

 [env]
 CC=/usr/bin/clang-3.5
 CXX=/usr/bin/clang++-3.5

A profile file can be stored in the default profile folder, or anywhere else in your project file structure. To use the configuration specified in a profile file, pass in the file as a command line argument as shown in the example below:
配置文件可以存储在默认配置文件文件夹中,也可以存储在项目文件结构中的任何其他位置。要使用配置文件中指定的配置,请将该文件作为命令行参数传入,如下例所示:

$ conan create . demo/testing -pr=clang_3.5

Continuing with the example of Poco, instead of passing in a long list of command line arguments, we can define a handy profile that defines them all and pass that to the command line when installing the project dependencies.
继续以 Poco 为例,我们可以定义一个方便的配置文件来定义所有参数,并在安装项目依赖项时将其传递到命令行,而不是传递一长串命令行参数。

A profile to install dependencies as shared and in debug mode would look like this:
在调试模式下以共享方式安装依赖项的配置文件是这样的

debug_shared

 include(default)

 [settings]
 build_type=Debug

 [options]
 poco:shared=True
 poco:enable_apacheconnector=False
 openssl:shared=True

To install dependencies using the profile file, we would use:
要使用配置文件安装依赖项,我们可以使用

$ conan install .. -pr=debug_shared

We could also create a new profile to use a different compiler version and store that in our project directory. For example:
我们还可以创建一个新的配置文件,使用不同的编译器版本,并将其存储在我们的项目目录中。例如

poco_clang_3.5

 include(clang_3.5)

 [options]
 poco:shared=True
 poco:enable_apacheconnector=False
 openssl:shared=True

To install dependencies using this new profile, we would use:
要使用这个新配置文件安装依赖项,我们可以使用

$ conan install .. -pr=../poco_clang_3.5

You can specify multiple profiles in the command line. The applied configuration will be the composition of all the profiles applied in the order they are specified:
您可以在命令行中指定多个配置文件。应用的配置将是按指定顺序应用的所有配置文件的组合:

$ conan install .. -pr=../poco_clang_3.5 -pr=my_build_tool1 -pr=my_build_tool2

See also
Read more about Profiles for full reference. There is a Conan command, conan profile, that can help inspecting and managing profiles. Profiles can be also shared and installed with the conan config install command.
请阅读有关Profiles的更多信息,以获得全面参考。Conan 命令 conan profile 可以帮助检查和管理配置文件。还可以使用 conan config install 命令共享和安装配置文件。

你可能感兴趣的:(conan,使用conan包,使用配置文件,使用conan包-使用配置文件)