機能オプションオブジェクト (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'
に変換した機能を返します。
機能 | value = true
|
value = 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()
メソッドは、以下の位置引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
value |
bool |
上の表を参照してください。 |
|
feature.disable_if()
値がfalseの場合、オブジェクト自体を返します。オブジェクトが'enabled'
で値がtrueの場合、エラーを返します。オブジェクトが'auto'
または'disabled'
で値がtrueの場合、無効な機能を返します。
機能 | value = true
|
value = 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
は、特にdependency()
に渡す場合に、'auto'
機能の適用性を制限するのに役立ちます。
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()
メソッドは、以下の位置引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
value |
bool |
チェックする値 |
|
最後に、feature.disable_if()
は、以下のキーワード引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
error_message |
str |
チェックが失敗した場合に表示するエラーメッセージ |
|
feature.disabled()
機能が'disabled'
に設定されているかどうかを返します。
シグネチャ
bool disabled()
feature.enable_auto_if()
値がtrueの場合、'auto'
を'enabled'
に変換した機能を返します。
機能 | value = true
|
value = 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()
メソッドは、以下の位置引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
value |
bool |
上の表を参照してください。 |
|
feature.enable_if()
値がfalseの場合、オブジェクト自体を返します。オブジェクトが'disabled'
で値がtrueの場合、エラーを返します。オブジェクトが'auto'
または'enabled'
で値がtrueの場合、有効な機能を返します。
機能 | value = true
|
value = 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
は、特にdependency()
に渡す場合に、'auto'
機能の適用性を制限するのに役立ちます。
use_llvm = get_option('llvm').enable_if(with_clang).enable_if(with_llvm_libs)
dep_llvm = dependency('llvm', required: use_llvm)
引数
feature.enable_if()
メソッドは、以下の位置引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
value |
bool |
チェックする値 |
|
最後に、feature.enable_if()
は、以下のキーワード引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
error_message |
str |
チェックが失敗した場合に表示するエラーメッセージ |
|
feature.enabled()
機能が'enabled'
に設定されているかどうかを返します。
シグネチャ
bool enabled()
feature.require()
値がtrueの場合、オブジェクト自体を返します。オブジェクトが'enabled'
で値がfalseの場合、エラーを返します。オブジェクトが'auto'
または'disabled'
で値がfalseの場合、無効な機能を返します。
機能 | value = true
|
value = 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()
メソッドは、以下の位置引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
value |
bool |
チェックする値 |
|
最後に、feature.require()
は、以下のキーワード引数を受け付けます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
error_message |
str |
チェックが失敗した場合に表示するエラーメッセージ |
|
検索結果は次のとおりです。