summaryrefslogtreecommitdiff
path: root/docs/markdown/Configuration.md
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-08-22 23:08:44 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2017-08-22 23:08:44 +0300
commitf381284969a9641723cd0bce0768c7d6820e61c8 (patch)
treed831bfe0e7ca03c7d0dbbecb03301defff8643e7 /docs/markdown/Configuration.md
parent3ff76f62a2f65c56ccaae33dee2571bff69563bc (diff)
downloadmeson-f381284969a9641723cd0bce0768c7d6820e61c8.tar.gz
A full example for using the conf object. Closes #2235.
Diffstat (limited to 'docs/markdown/Configuration.md')
-rw-r--r--docs/markdown/Configuration.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/docs/markdown/Configuration.md b/docs/markdown/Configuration.md
index ae14e7b8f..9db6370b3 100644
--- a/docs/markdown/Configuration.md
+++ b/docs/markdown/Configuration.md
@@ -111,3 +111,44 @@ Will produce:
/* Set BAR if it is available */
#define BAR
```
+
+# A full example
+
+Generating and using a configuration file requires the following steps:
+
+ - generate the file
+ - create an include directory object for the directory that holds the file
+ - use it in a target
+
+We are going to use the traditional approach of generating a header
+file in the top directory. The common name is `config.h` but we're
+going to use an unique name. This avoids the problem of accidentally
+including the wrong header file when building a project with many
+subprojects.
+
+At the top level we generate the file:
+
+```meson
+configure_file(input : 'projconfig.h.in',
+ output : 'projconfig.h',
+ configuration : cdata_object)
+```
+
+Immediately afterwards we generate the include object.
+
+```meson
+configuration_inc = include_directories('.')
+```
+
+Finally we specify this in a target that can be in any subdirectory.
+
+```meson
+executable(..., include_directories : configuration_inc)
+```
+
+Now any source file in this target can include the configuration
+header like this:
+
+```c
+#include<projconfig.h>
+```