Add support for out-of-tree builds

This is a new PR on top of `next`. See #95 for the original discussion.