Allow building PHP plugin with mingw and cmake. Cleanup duplicate code.