Fixed major cmake bugs from refactoring