# XXX - ensure .../vcpkg/installed/x64-windows/tools/llvm is in your ENV{PATH}

set(CMAKE_AR "llvm-lib.exe" CACHE STRING "" FORCE)
set(CMAKE_ASM_MASM_COMPILER "ml64.exe" CACHE STRING "" FORCE)
set(CMAKE_C_COMPILER "clang-cl.exe" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER "clang-cl.exe" CACHE STRING "" FORCE)
set(CMAKE_LINKER "lld-link.exe" CACHE STRING "" FORCE) 
set(CMAKE_MT "mt.exe" CACHE STRING "" FORCE)
set(CMAKE_RC_COMPILER "rc.exe" CACHE STRING "" FORCE)

# XXX - copied from windows.cmake

if(NOT _VCPKG_WINDOWS_TOOLCHAIN)
  set(_VCPKG_WINDOWS_TOOLCHAIN 1)
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<STREQUAL:${VCPKG_CRT_LINKAGE},dynamic>:DLL>" CACHE STRING "")

  get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
  if(NOT _CMAKE_IN_TRY_COMPILE)

      if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
          set(VCPKG_CRT_LINK_FLAG_PREFIX "/MD")
      elseif(VCPKG_CRT_LINKAGE STREQUAL "static")
          set(VCPKG_CRT_LINK_FLAG_PREFIX "/MT")
      else()
          message(FATAL_ERROR "Invalid setting for VCPKG_CRT_LINKAGE: \"${VCPKG_CRT_LINKAGE}\". It must be \"static\" or \"dynamic\"")
      endif()

      set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc ${VCPKG_CXX_FLAGS}" CACHE STRING "")
      set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /W3 ${VCPKG_C_FLAGS}" CACHE STRING "")
      set(CMAKE_RC_FLAGS "-c65001 /DWIN32" CACHE STRING "")

      set(CMAKE_CXX_FLAGS_DEBUG "${VCPKG_CRT_LINK_FLAG_PREFIX}d /Zi /Ob0 /Od /RTC1 ${VCPKG_CXX_FLAGS_DEBUG}" CACHE STRING "")
      set(CMAKE_C_FLAGS_DEBUG "${VCPKG_CRT_LINK_FLAG_PREFIX}d /Zi /Ob0 /Od /RTC1 ${VCPKG_C_FLAGS_DEBUG}" CACHE STRING "")
      set(CMAKE_CXX_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_CXX_FLAGS_RELEASE}" CACHE STRING "")
      set(CMAKE_C_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_C_FLAGS_RELEASE}" CACHE STRING "")

      string(APPEND CMAKE_STATIC_LINKER_FLAGS_RELEASE_INIT " /nologo ")
      set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS} ${VCPKG_LINKER_FLAGS_RELEASE}" CACHE STRING "")
      set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS} ${VCPKG_LINKER_FLAGS_RELEASE}" CACHE STRING "")

      string(APPEND CMAKE_STATIC_LINKER_FLAGS_DEBUG_INIT "")
      string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS} ${VCPKG_LINKER_FLAGS_DEBUG} ")
      string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS} ${VCPKG_LINKER_FLAGS_DEBUG} ")
  endif()
endif()