LLVM with Clang Build Instructions
This guide explains how to set up, build, and test LLVM with Clang on your local machine.
Prerequisites
Before you start building LLVM and Clang, make sure the following software is installed:
- CMake (version 3.13 or higher)
- Ninja (recommended for faster builds)
- Python (for running tests)
- Git (optional for version control)
Installing Dependencies
Linux
sudo apt-get install cmake ninja-build python3 git
Windows
With Visual Studio
With WSL
sudo apt update
sudo apt install build-essential cmake ninja-build python3
MacOS
brew install cmake ninja python git
Cloning the LLVM Project
Clone the LLVM project from GitHub. This includes Clang and other subprojects
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
If you want to build a specific release, check out the corresponding tag. For example:
git checkout llvmorg-16.0.0
Configuring the Build
Create a separate directory for building the project:
mkdir build
cd build
Linux
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
../llvm
macOS
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
../llvm
Windows
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
../llvm
for the visual Studio
Configuring the Build
Create a separate directory for building the project:
mkdir build
cd build
cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release ../llvm
-DLLVM_ENABLE_PROJECTS=clang
: This enables Clang to be built alongside LLVM.-DCMAKE_BUILD_TYPE=Release
: Builds LLVM in release mode with optimizations.-DLLVM_TARGETS_TO_BUILD=X86
: You can specify the target architecture(s). ReplaceX86
with your desired architecture (e.g.,ARM
,AArch64
).
For other Cmake flag please visit Configure the build using CMake. It's recommended to use Ninja as the build system for faster builds.
If on windows you are facing any issue with the ninja build try with the Visual studio build or use WSL
Building LLVM with Clang
Once the configuration is complete, build the project:
ninja
If you are not using Ninja, you can use Make instead:
make
The build process can take some time depending on your machine's specifications.
Running Tests
After the build is complete, you can run the tests to ensure everything is working correctly:
ninja check-all
This command will run all available tests for LLVM, Clang, and other enabled subprojects.
Cleaning Up the Build
To clean the build directory, run:
ninja clean
Or with Make:
make clean
Short Summary
-
Prerequisites: Install CMake, Ninja, Python, and Git.
-
Install Dependencies:
- Linux:
sudo apt-get install cmake ninja-build python3 git
- Windows (WSL):
sudo apt update && sudo apt install build-essential cmake ninja-build python3
- macOS:
brew install cmake ninja python git
- Linux:
-
Clone the LLVM Project:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-1.0.0 # Optional for specific version -
Configure and Build
mkdir build
cd build
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" ../llvm
ninja
Additional Resources
For more details, refer to the official LLVM documentation: