Cmake build fixes

Almost done. Only one link issue left.