Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Created September 22, 2021 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friendlyanon/26f7ff71aaaad8bd595cf417cf0af7f4 to your computer and use it in GitHub Desktop.
Save friendlyanon/26f7ff71aaaad8bd595cf417cf0af7f4 to your computer and use it in GitHub Desktop.
Toolchain file to use LLVM Clang on Windows.
# Path to your LLVM Clang executables, I have mine in the PATH so I just name
# them directly
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
# Make sure CMake doesn't do something silly and just tell it that we are
# compiling for Windows on Windows
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CROSSCOMPILING 0)
# Set the triplet for the LLVM toolchain
set(CMAKE_C_COMPILER_TARGET x86_64-pc-windows)
set(CMAKE_CXX_COMPILER_TARGET x86_64-pc-windows)
# The version numbers below are specific to whatever you have installed and
# need updating when you update MSVC
# LLVM Clang uses the MSVC linker on Windows, so you must provide it with the
# MSVC system .lib files
set(CMAKE_EXE_LINKER_FLAGS_INIT [[-Xlinker /libpath:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64" -Xlinker /libpath:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64"]])
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}")
# Includes must be specified as SYSTEM, so warnings are suppressed
include_directories(
SYSTEM
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include"
"C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/ucrt"
"C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/um"
"C:/Program Files (x86)/Windows Kits/10/include/10.0.19041.0/shared"
)
# Windows.h ends up transitively in the includes, so let's try to make it more
# standards compliant
add_compile_definitions(WIN32_MEAN_AND_LEAN NOMINMAX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment