Add cmake support to have be able to build on windows with MSVC.

These are the changes we talked about about integrating CMake for the build process.
I also did some (pretty minor) code changes to get a build done on MSVC, had to implement a little windows specific logic that was missing.