I like out-of-tree builds. Out-of-tree builds are nice for lots of reasons. You
can have multiple builds of the same project coexisting side-by-side – for
example a debug build for development, a release build, and an instrumented
build for code coverage runs. All the generated build artifacts are together
underneath one directory which you can easily delete without having to maintain
make clean target, or place under
.gitignore without having to maintain a
growing set of patterns for the different kinds of artifacts. I was going to
write a post about this, but came across
this one by Jussi Pakkanen which covers a lot of the
ground I would have, so I’ll just link to it here.
Instead, this post is about an issue that arises when implementing out-of-tree builds in make, and the best approach I’ve found for dealing with it.