Added Cmake support, also fixed build bugs.