Fully migrate to Cmake.
Fix some compile issue.