What Are the Dependencies for Building LLVM? Essential Tools and Libraries Explained
Building LLVM requires CMake ≥3.20, a C++14-compatible compiler (GCC ≥7, Clang ≥6, or MSVC ≥2017), Git, Python ≥3.6, and system libraries including zlib and libxml2, with Ninja and LLD recommended for optimal performance.
The LLVM Project is a comprehensive compiler infrastructure toolkit that demands specific system prerequisites before compilation. According to the official llvm/llvm-project repository, understanding the dependencies for building LLVM is essential for successfully compiling the core libraries and optional components like Clang or LLD from source.
Core Dependencies for Building LLVM
Version Control with Git
You need Git to clone the monorepo from GitHub. As documented in llvm/docs/GettingStarted.md, the standard checkout command is:
git clone https://github.com/llvm/llvm-project.git
CMake Build System Generator
CMake ≥3.20 is mandatory for generating build files. The minimum version is enforced in llvm/cmake/modules/LLVMConfig.cmake. CMake supports multiple backends including Ninja, Make, and Visual Studio.
C++ Compiler Requirements
LLVM requires a compiler supporting C++14. Valid options include GCC ≥7, Clang ≥6, or MSVC ≥2017. The codebase uses a minimal C++14 subset to maintain broad compatibility, as verified by the top-level llvm/CMakeLists.txt.
Build Execution Tools
While GNU Make works, Ninja is the recommended build tool for fast parallel compilation. The documentation in llvm/docs/GettingStarted.md shows -G Ninja as the preferred generator.
System Libraries and Runtime Dependencies
Beyond build tools, LLVM links against several system libraries detected automatically by CMake modules in llvm/cmake/modules/. These include:
- zlib and libzstd for compression support
- libxml2 for XML processing capabilities
- libedit, ncurses, and libtinfo for terminal handling
- libffi for foreign function interface support
- libcurl for network operations
- libpng for image processing
- libpthread, libdl, libm, and libstdc++/libc++ for system threading and mathematics
Python for Testing and Utilities
Python ≥3.6 drives the lit test runner and specific CMake scripts. It is required for executing LLVM's regression tests via check-* targets and for utilities such as FileCheck, as configured through the LLVM_EXTERNAL_LIT option.
Optional but Recommended Components
LLD Linker
While not strictly required, LLD significantly reduces link times. Enable it with -DLLVM_USE_LINKER=lld during configuration, as noted in the Getting Started guide.
Additional Runtime Libraries
Optional projects require specific runtimes:
- OpenMP and libomp for parallelization support
- libc++ and libc++abi for standard library implementations
- compiler-rt and sanitizers for runtime instrumentation
Control these via the -DLLVM_ENABLE_PROJECTS flag defined in llvm/CMakeLists.txt.
How CMake Discovers Dependencies
When you run CMake from the top-level llvm directory, it executes Find modules like FindZLIB.cmake, FindLibXML2.cmake, and FindPython3.cmake to locate system packages. The process follows three stages:
- Generate the build directory using
cmake -S llvm -B build -G Ninja - Check for required tools and libraries via the Find modules
- Report missing dependencies immediately, before compilation begins
If a required library is missing, CMake aborts with a descriptive error referencing the specific module:
CMake Error at cmake/modules/FindZLIB.cmake:... (find_package):
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
This early validation behavior is detailed in llvm/docs/CMakePrimer.md, which explains how the build system prevents compilation failures by verifying prerequisites during the configuration phase.
Quick Start Build Example
Assuming all dependencies are installed, the standard build process follows these commands:
git clone --depth 1 https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -S llvm -B build -G Ninja \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_USE_LINKER=lld
ninja -C build
If tools are missing, CMake stops and lists the specific package needed, allowing you to install it via your system package manager (e.g., apt install cmake ninja-build clang on Ubuntu, or brew install cmake ninja on macOS).
Summary
- CMake ≥3.20, Git, and a C++14 compiler are mandatory for building LLVM
- Ninja is strongly recommended over Make for faster parallel builds
- System libraries (zlib, libxml2, ncurses) are automatically detected by CMake modules in
llvm/cmake/modules/ - Python ≥3.6 is required for running the test suite with lit
- LLD can accelerate linking when specified via
-DLLVM_USE_LINKER=lld - Missing dependencies trigger immediate CMake errors referencing specific
Find*.cmakemodules
Frequently Asked Questions
What is the minimum CMake version required to build LLVM?
LLVM requires CMake 3.20 or newer. This minimum is hardcoded in llvm/cmake/modules/LLVMConfig.cmake and enforced during the configuration phase. Attempting to build with older versions results in a fatal CMake error before any compilation begins.
Can I build LLVM using GNU Make instead of Ninja?
Yes, GNU Make is supported, but Ninja is strongly recommended. The LLVM documentation in llvm/docs/GettingStarted.md explicitly recommends Ninja (-G Ninja) for superior parallel build performance. Make can be used by specifying -G "Unix Makefiles", though build times will be significantly longer.
Which C++ standard does LLVM require?
LLVM source code requires C++14 support. The project maintains compatibility with GCC 7+, Clang 6+, and MSVC 2017+. The llvm/CMakeLists.txt file enforces this standard, rejecting compilers that lack the necessary language features.
How do I enable additional projects like Clang or LLD during the build?
Use the LLVM_ENABLE_PROJECTS CMake option to specify sub-projects. For example, -DLLVM_ENABLE_PROJECTS="clang;lld" includes both Clang and LLD. This list controls which components CMake builds alongside core LLVM libraries, as implemented in the top-level llvm/CMakeLists.txt.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →