Recommendation 0: Read the docs mainly. LLVM docs are actually good. This will cover some areas in between what's documented and what works. I'll try to eventually merge this into the mainline LLVM docs.
Recommendation 1: Create a shell just for LLVM. First create a batch script that sets the PATH to LLVM dependencies (called something like llvm-setup.bat
). Create a shortcut for cmd.exe. Have the shortcut run %comspec% /k "C:\path\to\llvm-setup.bat"
.
Here is what I ended up using
-
- @ECHO OFF
-
- :: LLVM Project Shell
- :: Sets path so that LLVM can build
- SET PROJDIR=C:\path\to\llvm-project
-
- SET "PATH=C:\Program Files (x86)\GnuWin32\bin;%PATH%"
- SET "PATH=C:\Program Files\SWIG\swigwin-4.1.1;%PATH%"
- SET "PATH=C:\Program Files\Python311;%PATH%"
- IF NOT DEFINED DevEnvDir (
- CALL "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" >nul
- )
- SET "PATH=C:\Program Files\CMake\bin;%PATH%"
-
- PUSHD %PROJDIR%
-
Some nice features of the batch script
Recommendation 2: PTAL at path\to\llvm-project\llvm\utils. Emacs, vim and editor configs are stored here.
Recommendation 3: Create your own build script that calls CMake (unless you want to manually type it in).
Here is what I ended up using (assuming you are using the LLVM shell, which gives access to 64 bit MSVC cl.exe)
-
- @ECHO OFF
-
- :: LLVM build
- SET DBGDIR=%PROJECTDIR%\build-debug
-
- :: Tells CMake to Use CL, not Clang, to build binaries
- SET CC=cl.exe
- SET CXX=cl.exe
-
- SET "NINJAx86=-GNinja -DLLVM_TARGETS_TO_BUILD=X86"
- SET "LLDBDBGOPTS=-DLLDB_TEST_DEBUG_TEST_CRASHES=1 -DLLDB_EXPORT_ALL_SYMBOLS=1"
- SET LLVMDIR=C:\LLVM\llvm
-
- IF NOT EXIST %DBGDIR% MKDIR %DBGDIR%
- cmake %NINJAx86% -B %DBGDIR% -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;lld;lldb" %LLDBDBGOPTS% -S %LLVMDIR%
-
Some suggestions and gotchas to look out for
-S C:\path\to\llvm-proj\llvm
, regardless of what you intend to build (passed to -DLLVM_ENABLE_PROJECTS
). I missed this and thought I needed to pass C:\path\to\llvm-proj\clang to build clang.x64
to vcvarsall.bat or open the 64 bit tooling VsDevCmd EVEN IF you are generating Ninja build files. Otherwise, it might use the default 32 bit linker.-DLLVM_TARGETS_TO_BUILD=X86
, replacing x86 with your desired architecture. Otherwise, you will build for all hardware architectures. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON