aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/Meson-sample.md
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@osg.samsung.com>2017-03-29 15:03:43 -0300
committerJussi Pakkanen <jpakkane@gmail.com>2017-04-26 17:56:33 +0300
commitb371875e02cce2fb3fbb9fbb8f07eb5817ae0e8f (patch)
tree6e1a3c34b1a85479d3b9f42ccd071096e637929b /docs/markdown/Meson-sample.md
parent7dc747ea54480c452b913e4bfe682ec67061c9bf (diff)
downloadmeson-b371875e02cce2fb3fbb9fbb8f07eb5817ae0e8f.zip
meson-b371875e02cce2fb3fbb9fbb8f07eb5817ae0e8f.tar.gz
meson-b371875e02cce2fb3fbb9fbb8f07eb5817ae0e8f.tar.bz2
docs: Import the website and wiki and build with hotdoc
This allows us to more easily have the documentation in sync with the source code as people will have to document new features etc right at the time where they implement it.
Diffstat (limited to 'docs/markdown/Meson-sample.md')
-rw-r--r--docs/markdown/Meson-sample.md58
1 files changed, 58 insertions, 0 deletions
diff --git a/docs/markdown/Meson-sample.md b/docs/markdown/Meson-sample.md
new file mode 100644
index 0000000..6f26f36
--- /dev/null
+++ b/docs/markdown/Meson-sample.md
@@ -0,0 +1,58 @@
+---
+short-description: Simple project step by step explanation
+...
+
+# Meson sample
+
+A Meson file that builds an executable looks like this.
+
+```meson
+project('simple', 'c')
+executable('myexe', 'source.c')
+```
+
+All Meson build definitions begin with the `project` command. It specifies the name of the project and what programming languages it uses. Here the project is called *simple* and it uses only the C programming language. All strings are single-quoted.
+
+On the next line we define a *build target*, in this case an executable called *myexe*. It consists of one source file. This is all the code that a user needs to write to compile an executable with Meson.
+
+Variables are fully supported. The above code snippet could also have been declared like this.
+
+```meson
+project('simple', 'c')
+src = 'source.c'
+executable('myexe', src)
+```
+
+Most executables consist of more than one source file. The easiest way to deal with this is to put them in an array.
+
+```meson
+project('simple', 'c')
+src = ['source1.c', 'source2.c', 'source3.c']
+executable('myexe', src)
+```
+
+Meson also supports the notion of *keyword arguments*. Indeed most arguments to functions can only be passed using them. The above snippet could be rewritten like this.
+
+```meson
+project('simple', 'c')
+src = ['source1.c', 'source2.c', 'source3.c']
+executable('myexe', sources : src)
+```
+
+These two formats are equivalent and choosing one over the other is mostly a question of personal preference.
+
+The `executable` command actually returns an *executable object*, which represents the given build target. It can be passed on to other functions, like this.
+
+```meson
+project('simple', 'c')
+src = ['source1.c', 'source2.c', 'source3.c']
+exe = executable('myexe', src)
+test('simple test', exe)
+```
+
+Here we create a unit test called *simple test*, and which uses the built executable. When the tests are run with the `ninja test` command, the built executable is run. If it returns zero, the test passes. A non-zero return value indicates an error, which Meson will then report to the user.
+
+A note to Visual Studio users
+-----
+
+There's a slight terminology difference between Meson and Visual Studio. A Meson *project* is the equivalent to a Visual Studio *solution*. That is, the topmost thing that encompasses all things to be built. A Visual Studio *project* on the other hand is the equivalent of a Meson top level build target, such as an executable or a shared library.