| 1 | \page buildmeson Build a Discord Bot Using Meson |
| 2 | |
| 3 | ## 1. Toolchain |
| 4 | |
| 5 | Before compiling, you will need to install `meson` on your system. To be sure that `meson` is installed, you can type the following command: |
| 6 | |
| 7 | ```bash |
| 8 | meson --version |
| 9 | 0.63.2 |
| 10 | ``` |
| 11 | |
| 12 | ## 2. Create a Meson project |
| 13 | |
| 14 | First, you'll need to go ahead and create an empty directory, we'll call it `meson-project`. |
| 15 | |
| 16 | Then, run this command: |
| 17 | |
| 18 | ```bash |
| 19 | meson init -l cpp |
| 20 | ``` |
| 21 | |
| 22 | ## 3. Configuring Your Meson Project |
| 23 | |
| 24 | Add the following line after the `project()` line in your `meson.build` file. |
| 25 | |
| 26 | ```yml |
| 27 | dpp = dependency('dpp') |
| 28 | ``` |
| 29 | |
| 30 | Add the following line in the executable section of your `meson.build` file. |
| 31 | |
| 32 | ```yml |
| 33 | dependencies: [dpp] |
| 34 | ``` |
| 35 | |
| 36 | Change the `cpp_std` value in the `project()` to `c++20`. Your `meson.build` should look like this: |
| 37 | |
| 38 | your meson.build should look like this. |
| 39 | ~~~~~~~~~~~~~~yml |
| 40 | project('discord-bot', 'cpp', |
| 41 | version : '0.1', |
| 42 | default_options : ['warning_level=3', |
| 43 | 'cpp_std=c++20']) |
| 44 | |
| 45 | dpp = dependency('dpp') |
| 46 | |
| 47 | exe = executable('discord', 'discord_bot.cpp', |
| 48 | install : true, dependencies: [dpp]) |
| 49 | |
| 50 | test('basic', exe) |
| 51 | ~~~~~~~~~~~~~~ |
| 52 | |
| 53 | Meson automatically generates a cpp for your project. And a test suite. |
| 54 | |
| 55 | ## 4. Building |
| 56 | |
| 57 | To build a Meson project, run the following: |
| 58 | |
| 59 | ```bash |
| 60 | meson setup builddir |
| 61 | meson compile -C builddir |
| 62 | ``` |
| 63 | |
| 64 | Now, your Meson project should be all setup! |
| 65 | |
| 66 | **Have fun!** |