Win build fixes

Fixes when using CMake and Visual Studio 2010.

Marked down the changes to be upstreamed more clearly. See individual commit messages for comments.