Simplify memory management with std::unique_ptr.
Fix cmake build.