|
|
|
name: feature
|
|
|
|
long_name: Feature option object
|
|
|
|
since: 0.47.0
|
|
|
|
description: Meson object representing a [`feature` options](Build-options.md#features)
|
|
|
|
|
|
|
|
methods:
|
|
|
|
- name: enabled
|
|
|
|
returns: bool
|
|
|
|
description: Returns whether the feature was set to `'enabled'`
|
|
|
|
|
|
|
|
- name: disabled
|
|
|
|
returns: bool
|
|
|
|
description: Returns whether the feature was set to `'disabled'`
|
|
|
|
|
|
|
|
- name: auto
|
|
|
|
returns: bool
|
|
|
|
description: Returns whether the feature was set to `'auto'`
|
|
|
|
|
|
|
|
- name: allowed
|
|
|
|
since: 0.59.0
|
|
|
|
returns: bool
|
|
|
|
description: Returns whether the feature was set to `'enabled'` or `'auto'`
|
|
|
|
|
|
|
|
- name: disable_auto_if
|
|
|
|
since: 0.59.0
|
|
|
|
returns: feature
|
|
|
|
description: |
|
|
|
|
Returns the feature, with `'auto'` converted to `'disabled'` if value is true.
|
|
|
|
|
|
|
|
| Feature / Condition | `value = true` | `value = false` |
|
|
|
|
| ------------------- | -------------- | --------------- |
|
|
|
|
| Enabled | Enabled | Enabled |
|
|
|
|
| Disabled | Disabled | Disabled |
|
|
|
|
| Auto | Disabled | Auto |
|
|
|
|
|
|
|
|
posargs:
|
|
|
|
value:
|
|
|
|
type: bool
|
|
|
|
description: See the table above
|
|
|
|
|
|
|
|
- name: enable_auto_if
|
|
|
|
since: 1.1.0
|
|
|
|
returns: feature
|
|
|
|
description: |
|
|
|
|
Returns the feature, with `'auto'` converted to `'enabled'` if value is true.
|
|
|
|
|
|
|
|
| Feature / Condition | `value = true` | `value = false` |
|
|
|
|
| ------------------- | -------------- | --------------- |
|
|
|
|
| Enabled | Enabled | Enabled |
|
|
|
|
| Disabled | Disabled | Disabled |
|
|
|
|
| Auto | Enabled | Auto |
|
|
|
|
|
|
|
|
posargs:
|
|
|
|
value:
|
|
|
|
type: bool
|
|
|
|
description: See the table above
|
|
|
|
|
|
|
|
- name: require
|
|
|
|
returns: feature
|
|
|
|
since: 0.59.0
|
|
|
|
description: |
|
|
|
|
Returns the object itself if the value is true; an error if the object is
|
|
|
|
`'enabled'` and the value is false; a disabled feature if the object
|
|
|
|
is `'auto'` or `'disabled'` and the value is false.
|
|
|
|
|
|
|
|
example: |
|
|
|
|
`require` is useful to restrict the applicability of `'auto'` features,
|
|
|
|
for example based on other features or on properties of the host machine:
|
|
|
|
|
|
|
|
```
|
|
|
|
if get_option('directx').require(host_machine.system() == 'windows',
|
|
|
|
error_message: 'DirectX only available on Windows').allowed() then
|
|
|
|
src += ['directx.c']
|
|
|
|
config.set10('HAVE_DIRECTX', true)
|
|
|
|
endif
|
|
|
|
```
|
|
|
|
|
|
|
|
posargs:
|
|
|
|
value:
|
|
|
|
type: bool
|
|
|
|
description: The value to check
|
|
|
|
|
|
|
|
kwargs:
|
|
|
|
error_message:
|
|
|
|
type: str
|
|
|
|
default: "''"
|
|
|
|
description: The error Message to print if the check fails
|
interpreter: add FeatureOption.enable_if and .disable_if
This adds two new methods, that are conceptually related in the same way
that `enable_auto_if` and `disable_auto_if` are. They are different
however, in that they will always replace an `auto` value with an
`enabled` or `disabled` value, or error if the feature is in the
opposite state (calling `feature(disabled).enable_if(true)`, for
example). This matters when the feature will be passed to
dependency(required : …)`, which has different behavior when passed an
enabled feature than an auto one.
The `disable_if` method will be controversial, I'm sure, since it
can be expressed via `feature.require()` (`feature.require(not
condition) == feature.disable_if(condition)`). I have two defences of
this:
1) `feature.require` is difficult to reason about, I would expect
require to be equivalent to `feature.enable_if(condition)`, not to
`feature.disable_if(not condition)`.
2) mixing `enable_if` and `disable_if` in the same call chain is much
clearer than mixing `require` and `enable_if`:
```meson
get_option('feat') \
.enable_if(foo) \
.disable_if(bar) \
.enable_if(opt)
```
vs
```meson
get_option('feat') \
.enable_if(foo) \
.require(not bar) \
.enable_if(opt)
```
In the first chain it's immediately obvious what is happening, in the
second, not so much, especially if you're not familiar with what
`require` means.
2 years ago
|
|
|
|
|
|
|
- name: enable_if
|
|
|
|
returns: feature
|
|
|
|
since: 1.1.0
|
|
|
|
description: |
|
|
|
|
Returns the object itself if the value is false; an error if the object is
|
|
|
|
`'disabled'` and the value is true; an enabled feature if the object
|
|
|
|
is `'auto'` or `'enabled'` and the value is true.
|
|
|
|
|
|
|
|
example: |
|
|
|
|
`enable_if` is useful to restrict the applicability of `'auto'` features,
|
|
|
|
particularly when passing them to [[dependency]]:
|
|
|
|
|
|
|
|
```
|
|
|
|
use_llvm = get_option('llvm').enable_if(with_clang).enable_if(with_llvm_libs)
|
|
|
|
dep_llvm = dependency('llvm', required: use_llvm)
|
interpreter: add FeatureOption.enable_if and .disable_if
This adds two new methods, that are conceptually related in the same way
that `enable_auto_if` and `disable_auto_if` are. They are different
however, in that they will always replace an `auto` value with an
`enabled` or `disabled` value, or error if the feature is in the
opposite state (calling `feature(disabled).enable_if(true)`, for
example). This matters when the feature will be passed to
dependency(required : …)`, which has different behavior when passed an
enabled feature than an auto one.
The `disable_if` method will be controversial, I'm sure, since it
can be expressed via `feature.require()` (`feature.require(not
condition) == feature.disable_if(condition)`). I have two defences of
this:
1) `feature.require` is difficult to reason about, I would expect
require to be equivalent to `feature.enable_if(condition)`, not to
`feature.disable_if(not condition)`.
2) mixing `enable_if` and `disable_if` in the same call chain is much
clearer than mixing `require` and `enable_if`:
```meson
get_option('feat') \
.enable_if(foo) \
.disable_if(bar) \
.enable_if(opt)
```
vs
```meson
get_option('feat') \
.enable_if(foo) \
.require(not bar) \
.enable_if(opt)
```
In the first chain it's immediately obvious what is happening, in the
second, not so much, especially if you're not familiar with what
`require` means.
2 years ago
|
|
|
```
|
|
|
|
|
|
|
|
posargs:
|
|
|
|
value:
|
|
|
|
type: bool
|
|
|
|
description: The value to check
|
|
|
|
|
|
|
|
kwargs:
|
|
|
|
error_message:
|
|
|
|
type: str
|
|
|
|
default: "''"
|
|
|
|
description: The error Message to print if the check fails
|
|
|
|
|
|
|
|
- name: disable_if
|
|
|
|
returns: feature
|
|
|
|
since: 1.1.0
|
|
|
|
description: |
|
|
|
|
Returns the object itself if the value is false; an error if the object is
|
|
|
|
`'enabled'` and the value is true; a disabled feature if the object
|
|
|
|
is `'auto'` or `'disabled'` and the value is true.
|
|
|
|
|
|
|
|
This is equivalent to `feature_opt.require(not condition)`, but may make
|
|
|
|
code easier to reason about, especially when mixed with `enable_if`
|
|
|
|
|
|
|
|
example: |
|
|
|
|
`disable_if` is useful to restrict the applicability of `'auto'` features,
|
|
|
|
particularly when passing them to [[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)
|
interpreter: add FeatureOption.enable_if and .disable_if
This adds two new methods, that are conceptually related in the same way
that `enable_auto_if` and `disable_auto_if` are. They are different
however, in that they will always replace an `auto` value with an
`enabled` or `disabled` value, or error if the feature is in the
opposite state (calling `feature(disabled).enable_if(true)`, for
example). This matters when the feature will be passed to
dependency(required : …)`, which has different behavior when passed an
enabled feature than an auto one.
The `disable_if` method will be controversial, I'm sure, since it
can be expressed via `feature.require()` (`feature.require(not
condition) == feature.disable_if(condition)`). I have two defences of
this:
1) `feature.require` is difficult to reason about, I would expect
require to be equivalent to `feature.enable_if(condition)`, not to
`feature.disable_if(not condition)`.
2) mixing `enable_if` and `disable_if` in the same call chain is much
clearer than mixing `require` and `enable_if`:
```meson
get_option('feat') \
.enable_if(foo) \
.disable_if(bar) \
.enable_if(opt)
```
vs
```meson
get_option('feat') \
.enable_if(foo) \
.require(not bar) \
.enable_if(opt)
```
In the first chain it's immediately obvious what is happening, in the
second, not so much, especially if you're not familiar with what
`require` means.
2 years ago
|
|
|
```
|
|
|
|
|
|
|
|
posargs:
|
|
|
|
value:
|
|
|
|
type: bool
|
|
|
|
description: The value to check
|
|
|
|
|
|
|
|
kwargs:
|
|
|
|
error_message:
|
|
|
|
type: str
|
|
|
|
default: "''"
|
|
|
|
description: The error Message to print if the check fails
|