file(TO_CMAKE_PATH $ENV{VCTOOLSINSTALLDIR} VCTOOLSINSTALLDIR)
file(TO_CMAKE_PATH $ENV{WINDOWSSDKDIR} WINDOWSSDKDIR)
file(TO_CMAKE_PATH $ENV{WINDOWSSDKLIBVERSION} WINDOWSSDKLIBVERSION)
set(msvcbin ${VCTOOLSINSTALLDIR}/bin/HostX86/${MSVC_ARCHITECTURE})
set(CMAKE_C_COMPILER "${msvcbin}/cl.exe")
set(CMAKE_CXX_COMPILER "${msvcbin}/cl.exe")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(MSVC_LIBRARY_PATH
    "${VCTOOLSINSTALLDIR}/lib/${MSVC_ARCHITECTURE}"
    "${WINDOWSSDKDIR}/lib/${WINDOWSSDKLIBVERSION}/ucrt/${MSVC_ARCHITECTURE}"
    "${WINDOWSSDKDIR}/lib/${WINDOWSSDKLIBVERSION}/um/${MSVC_ARCHITECTURE}")

foreach(x ${MSVC_LIBRARY_PATH})
    set(MSVC_LIBRARY_PATH_FLAGS "${MSVC_LIBRARY_PATH_FLAGS} /LIBPATH:\"${x}\"")
endforeach()

set(MSVC_LINKER_FLAGS "/DEBUG /DYNAMICBASE /NXCOMPAT /TLBID:1 ${MSVC_LIBRARY_PATH_FLAGS}")

set(CMAKE_EXE_LINKER_FLAGS ${MSVC_LINKER_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS "/DLL ${MSVC_LINKER_FLAGS}")
