-
Notifications
You must be signed in to change notification settings - Fork 2
Building LLVM from Sources
Using the Microsoft C++ Library Manager is the simplest way to install LLVM on Windows (x64). There are, however, some drawbacks. First, vcpkg will compile and install both the release and the debug version of LLVM, which requires a significant amount of free harddisk space during installation. Second, it typically takes a while before a new release of LLVM is integrated into the vcpkg distribution. Should any of these two factors present a problem, please refer to the instructions given below on how to build LLVM from the sources.
If the latest version of LLVM is not yet available as a vcpkg package or if you only want to compile the release or the debug version, you can build LLVM from the official project sources. As a prerequisite, make sure that you have a recent version of CMake for Windows and Python installed on your system. Then build LLVM by following the steps described below.
-
Clone the LLVM project repository from GitHub and create a separate build directory to avoid interfering with the source tree.
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
-
Create the Visual Studio 2019 projects for the build targets using CMake. It is recommended to build LLVM in
Debug
mode in order to be later able to also build the Oberon LLVM frontend inDebug
mode. If you prefer to build LLVM inRelease
mode, set theCMAKE_BUILD_TYPE
accordingly.cmake.exe ..\llvm -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_TOOLS=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_BUILD_BENCHMARKS=OFF -DLLVM_BUILD_LLVM_DYLIB=OFF -DLLVM_LINK_LLVM_DYLIB=OFF -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
Note that this command builds the LLVM libraries and tools, but does not build the examples, tests, and benchmarks. The option
LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
is currently required to enable the build using Visual Studio 2019 (Version 16.4), which is known to miscompile parts of LLVM. Please refer to the LLVM documentation for detailed explanations of the build options given above. -
Once the build targets have been created by CMake, LLVM can be built and installed using the following command. Note that the given configuration option needs to match the build type specified in the previous command, i.e.,
Debug
in the example given here.msbuild /m -p:Configuration=Debug INSTALL.vcxproj
As a default, this command will install the LLVM Compiler Infrastructure into the
C:\Program Files (x86)\LLVM
directory. As a consequence, the command prompt from which the command is run needs elevated privilege as, otherwise, it cannot write to that directory. If you would, therefore, like to install LLVM to a different directory, consider specifying theCMAKE_INSTALL_PREFIX
option in Step 2.
Building the Frontend
Using the Compiler
- Apple Clang Toolchain
- GCC Toolchain
- Microsoft MSVC Toolchain
- Just-in-Time Compilation
- Embedded Devices
Oberon Compatibility
Miscellaneous