Meson is a cross-platform build automation tool for C/C++. Its syntax is similar to Python’s, and is strongly typed but not Turing complete.
Meson requires a separate build
directory for compiler outputs. It takes an order of precedence for the default C/C++ compiler: GCC/G++, LLVM (Clang, Clang++), MSVC, and so on.
We have a few commands (assume they start with meson
):
setup build
— which sets up the Meson project inside thebuild
directory. This can be a different name, it just needs to be a specific directory.compile -C build
— which compiles the project to thebuild
directory.
Quick links:
Build file
The standard Meson build file is stored in meson.build
. We should ideally have one in our main project directory, and more files in any sub-directories.
We need to define several characteristics in our main build file:
project('name', 'lang')
— defines a project name, and the language which determines the compiler version. We can also add extra parameters:default_options : ['arr']
— allows us to specify things like language-version. For instance, we can set thec_std=gnu17
for the GNU version of C17.
subdir('dir')
should be used for any required subdirectories in the build step. Any local variables in themeson.build
files in those subdirectories are usable in the parent file.executable('name', ['files'])
— specifies the executable name and any files used to compile to it.dependency('lib')
— specifies a single library dependency (i.e., GTK). For each dependency, we need separatedependency()
calls.