set(CMAKE_SYSTEM_NAME Windows CACHE STRING "")

set(LLVM_PREFIX $ENV{SMAKE_LLVM_PREFIX})
set(LLVM_CLANG_PATH $ENV{SMAKE_LLVM_CLANG_PATH})
set(LLVM_MSVC_PATH $ENV{SMAKE_LLVM_MSVC_PATH})
set(LLVM_MSVC_VERSION $ENV{SMAKE_LLVM_MSVC_VERSION})
set(LLVM_WINDOWS_KITS_10_PATH $ENV{SMAKE_LLVM_WINDOWS_KITS_10_PATH})
set(LLVM_WINDOWS_KITS_10_VERSION $ENV{SMAKE_LLVM_WINDOWS_KITS_10_VERSION})

set(APPLE 0)
set(MSVC 1)
set(WIN32 1)
set(UNIX 0)

set(triple "x86_64-pc-windows-msvc")

set(CMAKE_LIB_SYSTEM_PATHS "" CACHE STRING "" FORCE)

# msvc dirs
include_directories(SYSTEM ${LLVM_MSVC_PATH}/include)
include_directories(SYSTEM ${LLVM_MSVC_PATH}/atlmfc/include)

set(CMAKE_LIB_SYSTEM_PATHS "${CMAKE_LIB_SYSTEM_PATHS} /libpath:\"${LLVM_MSVC_PATH}/lib/x64\"")
set(CMAKE_LIB_SYSTEM_PATHS "${CMAKE_LIB_SYSTEM_PATHS} /libpath:\"${LLVM_MSVC_PATH}/atlmfc/lib/x64\"")


# win kit dirs
include_directories(SYSTEM ${LLVM_WINDOWS_KITS_10_PATH}/Include)
include_directories(SYSTEM ${LLVM_WINDOWS_KITS_10_PATH}/Include/${LLVM_WINDOWS_KITS_10_VERSION}/ucrt)
include_directories(SYSTEM ${LLVM_WINDOWS_KITS_10_PATH}/Include/${LLVM_WINDOWS_KITS_10_VERSION}/um)
include_directories(SYSTEM ${LLVM_WINDOWS_KITS_10_PATH}/Include/${LLVM_WINDOWS_KITS_10_VERSION}/shared)

set(CMAKE_LIB_SYSTEM_PATHS "${CMAKE_LIB_SYSTEM_PATHS} /libpath:\"${LLVM_WINDOWS_KITS_10_PATH}/Lib/${LLVM_WINDOWS_KITS_10_VERSION}/ucrt/x64\"")
set(CMAKE_LIB_SYSTEM_PATHS "${CMAKE_LIB_SYSTEM_PATHS} /libpath:\"${LLVM_WINDOWS_KITS_10_PATH}/Lib/${LLVM_WINDOWS_KITS_10_VERSION}/um/x64\"")

foreach(lang C CXX)
  set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} --target=${triple} /DWIN32 /D_WINDOWS -D_MSC_VER=${LLVM_MSVC_VERSION} -fmsc-version=${LLVM_MSVC_VERSION} -fms-extensions -fms-compatibility -fdelayed-template-parsing")
endforeach()

set(CMAKE_C_COMPILER "${LLVM_PREFIX}clang-cl" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER "${LLVM_PREFIX}clang-cl" CACHE STRING "" FORCE)
set(CMAKE_ASM_MASM_COMPILER "ml64" CACHE STRING "" FORCE)
set(CMAKE_LIB "${LLVM_PREFIX}llvm-lib")
set(CMAKE_RC_COMPILER "${LLVM_PREFIX}llvm-rc")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LIB_SYSTEM_PATHS}" CACHE INTERNAL "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LIB_SYSTEM_PATHS}" CACHE INTERNAL "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS "" CACHE INTERNAL "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_LIB_SYSTEM_PATHS}" CACHE INTERNAL "" FORCE)

# some additional crypto-teric cmake stuff, for your pleasure:
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
