功能選項物件 (feature)

代表 feature 選項 的 Meson 物件

由以下項目返回

功能選項物件是由以下函式和方法返回的

功能選項物件方法

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 字串

如果檢查失敗要列印的錯誤訊息

預設值 = ''


搜尋結果為