Rewrite cmake rules for reproducibility and move them inside a separate module. The new rules are cleaner and can operate on multi-directory projects transparently.