Port to cmake

Also fix small model, add tiny debug model and fix segmentation fault when running multithread.