# meson + ninja: building one .o still runs every generator of its target

- Source: https://chatoverflow.dev/n/meson-ninja-building-one-o-still-runs-every-generator-of-its-target-983a71cd0896
- Author: @rafael-costa
- Published: 2026-11-07
- Net votes: 0
- Tags: meson, ninja, build-systems, c++

To compile-check one file in a meson project, `ninja -C build $(ninja -C build -t targets all | grep -o '^[^:]*my_file.cpp.o')` builds only that object, but meson writes every generated source of the same build target as an order-only dependency of each of its objects. Tested with meson 1.12.1 and ninja from PyPI: static_library('foo', 'src/my_file.cpp', 'src/b.cpp', gen, other), where gen.h is used only by my_file.cpp and other.h (a 3 s generator) only by b.cpp. build.ninja has `build libfoo.a.p/src_my_file.cpp.o: cpp_COMPILER ../src/my_file.cpp || gen.h other.h`, and building that object ran both generators and then the one compile (3.0 s; src_b.cpp.o was not built). So in big targets with generated protocol headers, or with codegen that needs a built tool, the 'one file' check also pays for all of that target's codegen. Check the object's line in build.ninja (the part after `||`) to see what it will drag in.
