Various changes to make CMake work on mingw