diff --git a/Meson Intro/main.c b/Meson Intro/main.c new file mode 100644 index 0000000..b4bd13c --- /dev/null +++ b/Meson Intro/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) +{ + printf("Hello there.\n"); + return 0; +} diff --git a/Meson Intro/meson.build b/Meson Intro/meson.build new file mode 100644 index 0000000..e6f219c --- /dev/null +++ b/Meson Intro/meson.build @@ -0,0 +1,2 @@ +project('tutorial', 'c') +executable('demo', 'main.c') diff --git a/Meson Intro/readme.md b/Meson Intro/readme.md new file mode 100644 index 0000000..7c3d47b --- /dev/null +++ b/Meson Intro/readme.md @@ -0,0 +1,43 @@ +# C++ with Meson +Install Meson and requirements +```bash +sudo apt install python3 python3-pip python3-setuptools python3-wheel ninja-build libgtk-3-dev +``` +```bash +pip3 install --user meson ninja +``` + +Everything installed right you can configure and build the build system by running `meson build`. If the folder `build` already exists, you can run `meson --reconfigure build` to let meson run the configuration again and update the build folder. +With the build folder existing, `cd build` and run `ninja`. Ninja will gather all dependencies and build every executable for you at once. All executables are then gathered in your build folder. In short summary: +```bash +meson builddir && cd builddir +meson compile +meson test +``` + +## Hello World +We start with the most basic programm "Hello World". First create the C file which holds the source. +Then create a Meson build description and write it in a file called `meson.build`. That's all we need. Build the application with the command: +```bash +meson setup builddir +cd builddir +meson compile +``` +Once the executable is built it run: +```bash +./demo +``` + +## Adding dependencies +More complex programms need dependencies and other files. The Meson file includes all instructions to find and use libraries, like GTK+: +``` +project('tutorial', 'c') +gtkdep = dependency('gtk+-3.0') +executable('demo', 'main.c', dependencies : gtkdep) +``` +To add multiple libraries, simply use seperate `dependency()` calls +``` +gtkdeps = [dependency('gtk+-3.0'), dependency('gtksourceview-3.0')] +``` + +All infos and more about Meson on their [Homepage](https://mesonbuild.com) \ No newline at end of file