The Build Directory & build.ninja
Meson is strict about one thing above all: the source tree is read-only. Everything Meson generates goes into the build directory, and the configuration that went into a build directory (compiler, cross file, options) is fixed for its lifetime, except for the options you change explicitly with meson configure. In-source builds are refused outright:
bash · try it yourself
mkdir -p p && cd p
echo "project('p', 'c')" > meson.build
meson setup . 2>&1 | tail -2
ERROR: Source and build directories must not be the same. Create a pristine build directory.
What is in a build directory
bash · try it yourself
mkdir -p tool && cd tool
cat > meson.build <<'M'
project('tool', 'c')
executable('tool', 'main.c', 'util.c')
M
echo 'int util(void); int main(void) { return util(); }' > main.c
echo 'int util(void) { return 0; }' > util.c
meson setup build > /dev/null
meson compile -C build -j 1 > /dev/null
find build -maxdepth 2 -not -path '*/meson-private/*' | sortbuild
build/.gitignore
build/.hgignore
build/.ninja_deps
build/.ninja_log
build/CACHEDIR.TAG
build/build.ninja
build/compile_commands.json
build/meson-info
build/meson-info/intro-benchmarks.json
build/meson-info/intro-buildoptions.json
build/meson-info/intro-buildsystem_files.json
build/meson-info/intro-compilers.json
build/meson-info/intro-dependencies.json
build/meson-info/intro-install_plan.json
build/meson-info/intro-installed.json
build/meson-info/intro-machines.json
build/meson-info/intro-projectinfo.json
build/meson-info/intro-targets.json
build/meson-info/intro-tests.json
build/meson-info/meson-info.json
build/meson-logs
build/meson-logs/meson-log.txt
build/meson-logs/meson-setup.txt
build/meson-private
build/tool
build/tool.p
build/tool.p/main.c.o
build/tool.p/util.c.o
| Entry | Purpose |
|---|---|
build.ninja |
the generated build file, run by Ninja |
compile_commands.json |
written on every setup, for clangd/clang-tidy and editors (CMake needs CMAKE_EXPORT_COMPILE_COMMANDS for this) |
tool.p/ |
the object files of target tool (.p = "private") |
meson-info/ |
the machine-readable description of the build, read by meson introspect and IDEs |
meson-logs/meson-log.txt |
the full configure log: every compiler check, with the command and its output |
meson-private/ |
Meson's internal state (pickled coredata.dat, build.dat, generated check programs). Never edit it |
CACHEDIR.TAG |
tells backup tools the directory is a cache that can be skipped |
A peek at build.ninja
You never edit build.ninja (it is regenerated whenever a meson.build changes), but reading it shows exactly what Meson asked for. The Make & Ninja course compares it with CMake's.
bash · try it yourself
mkdir -p tool && cd tool
cat > meson.build <<'M'
project('tool', 'c')
executable('tool', 'main.c')
M
echo 'int main(void) { return 0; }' > main.c
meson setup build > /dev/null
grep -A3 '^rule c_COMPILER