aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/Disabler.md
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-12-05 01:10:50 +0200
committerGitHub <noreply@github.com>2017-12-05 01:10:50 +0200
commitbc83c58d37421b84c5420356a79e04ade2b851a7 (patch)
tree1c47671d6d458ac4d7ec367d3cac716abedf8da8 /docs/markdown/Disabler.md
parent87e6201214eda0941d2a2279e12a575fc27d21bb (diff)
parentd3dcef7efc1df3b7a645eb6dc75c4a66a9131cb9 (diff)
downloadmeson-bc83c58d37421b84c5420356a79e04ade2b851a7.zip
meson-bc83c58d37421b84c5420356a79e04ade2b851a7.tar.gz
meson-bc83c58d37421b84c5420356a79e04ade2b851a7.tar.bz2
Merge pull request #2731 from mesonbuild/disabler
Created disabler object type
Diffstat (limited to 'docs/markdown/Disabler.md')
-rw-r--r--docs/markdown/Disabler.md65
1 files changed, 65 insertions, 0 deletions
diff --git a/docs/markdown/Disabler.md b/docs/markdown/Disabler.md
new file mode 100644
index 0000000..2d50c5c
--- /dev/null
+++ b/docs/markdown/Disabler.md
@@ -0,0 +1,65 @@
+---
+short-description: Disabling options
+...
+
+# Disabling parts of the build (available since 0.44.0)
+
+The following is a common fragment found in many projects:
+
+```meson
+dep = dependency('foo')
+
+# In some different directory
+
+lib = shared_library('mylib', 'mylib.c',
+ dependencies : dep)
+
+# And ín a third directory
+
+exe = executable('mytest', 'mytest.c',
+ link_with : lib)
+test('mytest', exe)
+```
+
+This works fine but gets a bit inflexible when you want to make this
+part of the build optional. Basically it reduces to adding `if/else`
+statements around all target invocations. Meson provides a simpler way
+of achieving the same with a disabler object.
+
+A disabler object is created with the `disabler` function:
+
+```meson
+d = disabler()
+```
+
+The only thing you can do to a disabler object is to ask if it has
+been found:
+
+```meson
+f = d.found() # returns false
+```
+
+Any other statement that uses a disabler object will immediately
+return a disabler. For example assuming that `d` contains a disabler
+object then
+
+```meson
+d2 = some_func(d) # value of d2 will be disabler
+d3 = true or d2 # value of d3 will be disabler
+if d # neither branch is evaluated
+```
+
+Thus to disable every target that depends on the dependency given
+above, you can do something like this:
+
+```meson
+if use_foo_feature
+ d = dependency('foo')
+else
+ d = disabler()
+endif
+```
+
+This concentrates the handling of this option in one place and other
+build definition files do not need to be sprinkled with `if`
+statements. \ No newline at end of file