ported most of configure.ac to cmake