特性选项对象 (feature)
表示 feature 选项 的 Meson 对象
由以下函数和方法返回
特性选项对象由以下函数和方法返回
get_option()feature.disable_auto_if()feature.disable_if()feature.enable_auto_if()feature.enable_if()feature.require()
特性选项对象方法
feature.allowed()
返回特性是否设置为 'enabled' 或 'auto'
签名
(自 0.59.0)
bool allowed()
feature.auto()
返回特性是否设置为 'auto'
签名
bool auto()
feature.disable_auto_if()
返回特性,如果值为 true,则将 'auto' 转换为 'disabled'。
| 特性 | 值 = true
|
值 = false
|
|---|---|---|
| 自动 | 禁用 | 自动 |
| 启用 | 启用 | 启用 |
| 禁用 | 禁用 | 禁用 |
签名
(自 0.59.0)
# Returns the feature, with `'auto'` converted to `'disabled'` if value is true
feature disable_auto_if(
bool value, # See the table above
)
示例
disable_auto_if 用于在互斥依赖项(提供相同 API)中,如果其中一个或两个都可用,则优先使用其中一个。
# '-Dfoo=auto -Dbar=enabled' will not pick foo even if installed.
use_bar = get_option('bar')
use_foo = get_option('foo').disable_auto_if(use_bar.enabled())
dep_foo = dependency('foo', required: use_foo)
if not dep_foo.found()
dep_foo = dependency('bar', required: use_bar)
endif
参数
feature.disable_auto_if() 方法接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
值 |
布尔值 |
参见上表 |
|
feature.disable_if()
如果值为 false,则返回对象本身;如果对象为 'enabled' 且值为 true,则返回错误;如果对象为 'auto' 或 'disabled' 且值为 true,则返回禁用的特性。
| 特性 | 值 = true
|
值 = false
|
|---|---|---|
| 自动 | 禁用 | 自动 |
| 启用 | 错误 | 启用 |
| 禁用 | 禁用 | 禁用 |
这等效于 feature_opt.require(not condition),但可能使代码更容易理解,尤其是在与 enable_if 混用时。
签名
(自 1.1.0)
# Returns the object itself if the value is false; an error if the object is
feature disable_if(
bool value, # The value to check
# Keyword arguments:
error_message : str # The error message to print if the check fails
)
示例
disable_if 用于限制 'auto' 特性的适用性,特别是在将其传递给 dependency() 时。
use_os_feature = get_option('foo') \
.disable_if(host_machine.system() == 'darwin', error_message : 'os feature not supported on MacOS')
dep_os_feature = dependency('os_feature', required: use_os_feature)
参数
feature.disable_if() 方法接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
值 |
布尔值 |
要检查的值 |
|
最后,feature.disable_if() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
error_message |
字符串 |
如果检查失败,要打印的错误消息 |
|
feature.disabled()
返回特性是否设置为 'disabled'
签名
bool disabled()
feature.enable_auto_if()
返回特性,如果值为 true,则将 'auto' 转换为 'enabled'。
| 特性 | 值 = true
|
值 = false
|
|---|---|---|
| 自动 | 启用 | 自动 |
| 启用 | 启用 | 启用 |
| 禁用 | 禁用 | 禁用 |
签名
(自 1.1.0)
# Returns the feature, with `'auto'` converted to `'enabled'` if value is true
feature enable_auto_if(
bool value, # See the table above
)
参数
feature.enable_auto_if() 方法接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
值 |
布尔值 |
参见上表 |
|
feature.enable_if()
如果值为 false,则返回对象本身;如果对象为 'disabled' 且值为 true,则返回错误;如果对象为 'auto' 或 'enabled' 且值为 true,则返回启用的特性。
| 特性 | 值 = true
|
值 = false
|
|---|---|---|
| 自动 | 启用 | 自动 |
| 启用 | 启用 | 启用 |
| 禁用 | 错误 | 禁用 |
签名
(自 1.1.0)
# Returns the object itself if the value is false; an error if the object is
feature enable_if(
bool value, # The value to check
# Keyword arguments:
error_message : str # The error message to print if the check fails
)
示例
enable_if 用于限制 'auto' 特性的适用性,特别是在将其传递给 dependency() 时。
use_llvm = get_option('llvm').enable_if(with_clang).enable_if(with_llvm_libs)
dep_llvm = dependency('llvm', required: use_llvm)
参数
feature.enable_if() 方法接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
值 |
布尔值 |
要检查的值 |
|
最后,feature.enable_if() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
error_message |
字符串 |
如果检查失败,要打印的错误消息 |
|
feature.enabled()
返回特性是否设置为 'enabled'
签名
bool enabled()
feature.require()
如果值为 true,则返回对象本身;如果对象为 'enabled' 且值为 false,则返回错误;如果对象为 'auto' 或 'disabled' 且值为 false,则返回禁用的特性。
| 特性 | 值 = true
|
值 = false
|
|---|---|---|
| 自动 | 自动 | 禁用 |
| 启用 | 启用 | 错误 |
| 禁用 | 禁用 | 禁用 |
签名
(自 0.59.0)
# Returns the object itself if the value is true; an error if the object is
feature require(
bool value, # The value to check
# Keyword arguments:
error_message : str # The error message to print if the check fails
)
示例
require 用于限制 'auto' 特性的适用性,例如基于其他特性或主机属性。
if get_option('directx').require(host_machine.system() == 'windows',
error_message: 'DirectX only available on Windows').allowed()
src += ['directx.c']
config.set10('HAVE_DIRECTX', true)
endif
参数
feature.require() 方法接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
值 |
布尔值 |
要检查的值 |
|
最后,feature.require() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
error_message |
字符串 |
如果检查失败,要打印的错误消息 |
|
搜索结果为