Fix out-of-tree builds

Fixes #1479