Skip to content
Latchkey

meson setup: Configure a Meson Build

meson setup <builddir> configures a Meson project into a build directory, detecting the toolchain and applying build options.

Meson always builds out-of-source and pairs with Ninja by default. The setup step reads meson.build, detects compilers and dependencies, and writes a Ninja build.

What it does

meson setup reads meson.build from the source tree, probes the compiler and dependencies, applies build options, and generates a Ninja build in the build directory. Reconfiguring an existing build dir needs --reconfigure.

Common usage

Terminal
meson setup build --buildtype=release
meson setup build -Dprefix=/usr/local -Dwerror=true
meson setup build --cross-file arm.ini
meson setup --reconfigure build

Options

FlagWhat it does
--buildtype <type>plain, debug, debugoptimized, release, minsize
-D<option>=<value>Set a built-in or project option (e.g. -Dprefix=)
--prefix <path>Install prefix (same as -Dprefix)
--cross-file <file>Cross-compilation definition file
--native-file <file>Native build machine definition file
--reconfigureRe-run setup on an existing build directory
--wipeWipe and reconfigure the build directory

In CI

Set --buildtype=release explicitly (the default is debug). Install a compiler and ninja (apt-get install build-essential ninja-build meson) before running. Use --wipe when a cached build dir was created with a stale toolchain rather than deleting it by hand.

Common errors in CI

"ERROR: Unknown compiler(s): ..." or "ERROR: No such command 'setup'" points at a missing compiler or too-old Meson. "ERROR: Neither a source directory nor a build directory..." means the build dir was already configured; add --reconfigure or --wipe. "ERROR: Dependency 'foo' not found" means a pkg-config dependency is missing; install its -dev package. "Unknown options: -Dbar" means the option name is wrong.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →