| 1 |
--- |
| 2 |
short-description: Project templates |
| 3 |
... |
| 4 |
|
| 5 |
# Project templates |
| 6 |
|
| 7 |
To make it easier for new developers to start working, Meson ships a |
| 8 |
tool to generate the basic setup of different kinds of projects. This |
| 9 |
functionality can be accessed with the `meson init` command. A typical |
| 10 |
project setup would go like this: |
| 11 |
|
| 12 |
```console |
| 13 |
$ mkdir project_name |
| 14 |
$ cd project_name |
| 15 |
$ meson init --language=c --name=myproject --version=0.1 |
| 16 |
``` |
| 17 |
|
| 18 |
This would create the build definitions for a helloworld type |
| 19 |
project. The result can be compiled as usual. For example it |
| 20 |
could be done like this: |
| 21 |
|
| 22 |
``` |
| 23 |
$ meson setup builddir |
| 24 |
$ meson compile -C builddir |
| 25 |
``` |
| 26 |
|
| 27 |
The generator has many different projects and settings. They can all |
| 28 |
be listed by invoking the command `meson init --help`. |
| 29 |
|
| 30 |
This feature is available since Meson version 0.45.0. |
| 31 |
|
| 32 |
# Generate a build script for an existing project |
| 33 |
|
| 34 |
With `meson init` you can generate a build script for an existing |
| 35 |
project with existing project files by running the command in the |
| 36 |
root directory of your project. Meson currently supports this |
| 37 |
feature for `executable`, and `jar` projects. |
| 38 |
|
| 39 |
# Build after generation of template |
| 40 |
|
| 41 |
It is possible to have Meson generate a build directory from the |
| 42 |
`meson init` command without running `meson setup`. This is done |
| 43 |
by passing `-b` or `--build` switch. |
| 44 |
|
| 45 |
```console |
| 46 |
$ mkdir project_name |
| 47 |
$ cd project_name |
| 48 |
$ meson init --language=c --name=myproject --version=0.1 --build |
| 49 |
``` |