Several fixes to cmake build system