set(CMAKE_SYSTEM_NAME Windows)
if ("${SYSTEM_PROCESSOR}" MATCHES "^(([Xx]|[Ii][3-6])86|[Pp][Ee][Nn][Tt][Ii][Uu][Mm])$")
    set(ARCH i686)
else ()
    set(ARCH x86_64)
endif ()
string(REGEX REPLACE "^i686$" "i386" SYSTEM_PROCESSOR ${ARCH})
set(CMAKE_C_COMPILER ${ARCH}-w64-mingw32-gcc)
set(CMAKE_C_COMPILER_TARGET ${SYSTEM_PROCESSOR}-pc-mingw32)
set(CMAKE_CXX_COMPILER ${ARCH}-w64-mingw32-g++)
set(CMAKE_CXX_COMPILER_TARGET ${SYSTEM_PROCESSOR}-pc-mingw32)
set(CMAKE_RC_COMPILER ${ARCH}-w64-mingw32-windres)
set(_CMAKE_TOOLCHAIN_PREFIX ${ARCH}-w64-mingw32-)
