To build everything, do this:

$ git clone --depth 1 --branch llvmorg-19.1.0 https://github.com/llvm/llvm-project.git
$ cmake -S llvm-project/llvm -B llvm-project/build \
        -DCMAKE_BUILD_TYPE=Release \
        -DLLVM_ENABLE_PROJECTS=all \
        -DLLVM_ENABLE_RUNTIMES=all
$ cmake --build llvm-project/build -j8
$ cmake --install llvm-project/build --prefix /usr/local  # or somewhere else

You might also be interested in the following build flags for the first CMake command:

  • -DLLVM_ENABLE_ASSERTIONS=ON -- good for debugging
  • -DLLVM_ENABLE_EH=ON -- enable if your application uses C++ exceptions
  • -DLLVM_ENABLE_RTTI=ON -- enable if your application uses C++ RTTI

Also see the upstream documentation: https://llvm.org/docs/CMake.html


Note that some of the LLVM projects can only be built with clang. I won't get into bootstrapping issues, but if the build fails, you can winnow down the list of projects from all to a subset of the following: clang, clang-tools-extra, cross-project-tests, libc, libclc, lld, lldb, openmp, polly, and pstl.

You can also reduce the list of runtimes to a subset of compiler-rt, libc, libcxx, libcxxabi, libunwind, and openmp.

Note that LLVM_ENABLE_PROJECTS and LLVM_ENABLE_RUNTIMES should not overlap. The latter builds each target with the just-built clang.

Answer from Alex Reinking on Stack Overflow
🌐
LLVM
llvm.org › docs › CMake.html
Building LLVM with CMake — LLVM 23.0.0git documentation
Execute this command in the shell replacing path/to/llvm/source/root with the path to the root of your LLVM source tree: ... CMake will detect your development environment, perform a series of tests, and generate the files required for building LLVM. CMake will use default values for all build ...
🌐
LLVM
llvm.org › docs › GettingStarted.html
Getting Started with the LLVM System — LLVM 23.0.0git documentation
Stand-alone builds allow you to build a sub-project against a pre-built version of the clang or llvm libraries that is already present on your system. You can use the source code from a standard checkout of the llvm-project (as described above) to do stand-alone builds, but you may also build ...
Discussions

installation - How do you build all of LLVM? - Stack Overflow
I recently built and installed llvm to my system with the expectation that this would be what is neccessary to build qtcreator: https://paste.ubuntu.com/p/23GCCS5xxS/ Based on what I saw there, I s... More on stackoverflow.com
🌐 stackoverflow.com
What is considered best practice to get LLVM working on Windows?
The Zig project hosts prebuilt LLVM binaries for windows: https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows Their prebuilt binaries seem to have much more included than the official LLVM windows package. It's insane that this is the easiest way to get LLVM on windows, but it's the best I've come across. EDIT: Looks like there are also build instructions there, that could be helpful too More on reddit.com
🌐 r/Compilers
21
7
November 3, 2021
how to build llvm-hs from source

Create a cabal project that depends on llvm-hs and use https://cabal.readthedocs.io/en/3.6/cabal-project.html#specifying-packages-from-remote-version-control-locations to specify the commit -- if llvm-hs has a checked-in *.cabal file (either not using hpack, not checked in the generated file).

More on reddit.com
🌐 r/haskell
2
5
April 15, 2022
Why is Nixpkgs suddenly building everything from source?
Usually most of packages are not built from source, but rather automatically downloaded from https://cache.nixos.org/ - but not all binaries are always available there (e.g. if you're using "too new" nixpkgs for which the artifacts simply haven't been built yet). To diagnose this problem, could you tell us which nixpkgs' version are you using? If you're using Nix Flakes, posting flake.lock would help; if you're not using flakes, then I guess nix-channel --list / sudo nix-channel --list. More on reddit.com
🌐 r/NixOS
13
16
December 4, 2021
🌐
Arthur O’Dwyer
quuxplusone.github.io › blog › 2019 › 11 › 09 › llvm-from-scratch
How to build LLVM from source, monorepo version
Here we will instruct CMake to build Clang again, using the Clang we just built. There is apparently an official way to bootstrap Clang (probably out-of-date). However, I use an approach inspired by the CMake FAQ. Note that we will not be installing Clang over top of the system compiler; that would be super dangerous and you should never do it! mkdir $ROOT/llvm-project/build2 cd $ROOT/llvm-project/build2 CXX="$ROOT/llvm-project/build/bin/clang++" \ cmake -G Ninja \ -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \ -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \ -DLIBCXXABI_USE_LLVM_UNWINDER=OFF \ -DCOMPILER_RT_USE_LLVM_UNWINDER=OFF \ -DCMAKE_BUILD_TYPE=RelWithDebInfo ../llvm ninja clang cxx ninja check-clang check-cxx
🌐
GitHub
github.com › llvm › llvm-project
GitHub - llvm/llvm-project: The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. · GitHub
3 days ago - This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM. Other components include: the libc++ C++ standard library, the LLD linker, and more.
Starred by 39K users
Forked by 17.6K users
Languages   LLVM 41.2% | C++ 30.4% | C 12.5% | Assembly 11.2% | MLIR 1.6% | Python 0.8%
Top answer
1 of 2
19

To build everything, do this:

$ git clone --depth 1 --branch llvmorg-19.1.0 https://github.com/llvm/llvm-project.git
$ cmake -S llvm-project/llvm -B llvm-project/build \
        -DCMAKE_BUILD_TYPE=Release \
        -DLLVM_ENABLE_PROJECTS=all \
        -DLLVM_ENABLE_RUNTIMES=all
$ cmake --build llvm-project/build -j8
$ cmake --install llvm-project/build --prefix /usr/local  # or somewhere else

You might also be interested in the following build flags for the first CMake command:

  • -DLLVM_ENABLE_ASSERTIONS=ON -- good for debugging
  • -DLLVM_ENABLE_EH=ON -- enable if your application uses C++ exceptions
  • -DLLVM_ENABLE_RTTI=ON -- enable if your application uses C++ RTTI

Also see the upstream documentation: https://llvm.org/docs/CMake.html


Note that some of the LLVM projects can only be built with clang. I won't get into bootstrapping issues, but if the build fails, you can winnow down the list of projects from all to a subset of the following: clang, clang-tools-extra, cross-project-tests, libc, libclc, lld, lldb, openmp, polly, and pstl.

You can also reduce the list of runtimes to a subset of compiler-rt, libc, libcxx, libcxxabi, libunwind, and openmp.

Note that LLVM_ENABLE_PROJECTS and LLVM_ENABLE_RUNTIMES should not overlap. The latter builds each target with the just-built clang.

2 of 2
3

These are the steps I use taken from here:

mkdir llvm
cd llvm

git clone https://github.com/llvm/llvm-project.git .
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git
git clone https://github.com/intel/opencl-clang.git
git clone https://github.com/KhronosGroup/SPIRV-Headers.git ./llvm/projects/SPIRV-Headers
git clone https://github.com/intel/vc-intrinsics.git ./llvm/projects/vc-intrinsics

mkdir build
cd build

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=”X86″ -DLLVM_ENABLE_PROJECTS=”clang” -DLLVM_EXTERNAL_PROJECTS=”llvm-spirv;opencl-clang” -DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=”../SPIRV-LLVM-Translator” -DLLVM_EXTERNAL_OPENCL_CLANG_SOURCE_DIR=”../opencl-clang” ../llvm

make opencl-clang
🌐
Arthur O’Dwyer
quuxplusone.github.io › blog › 2018 › 04 › 16 › building-llvm-from-source
How to build LLVM from source – Arthur O'Dwyer
April 16, 2018 - Making clang will build both clang and clang++. Making cxx will build libc++ (and also libc++abi, which is included in the libcxx repo). Making check-$FOO will build and run the test suite for $FOO: ... cd $ROOT/llvm/build ./bin/llvm-lit -sv ../test/Analysis ./bin/llvm-lit -sv ../tools/clang/test/ARCMT ./bin/llvm-lit -sv ../projects/libcxx/test/std/re
🌐
AMD ROCm
rocm.docs.amd.com › projects › llvm-project › en › latest › LLVM › llvm › html › CMake.html
Building LLVM with CMake — LLVM 22.0.0git documentation
Execute this command in the shell replacing path/to/llvm/source/root with the path to the root of your LLVM source tree: ... CMake will detect your development environment, perform a series of tests, and generate the files required for building LLVM. CMake will use default values for all build ...
Find elsewhere
🌐
Inl
mooseframework.inl.gov › getting_started › installation › manual_installation_llvm.html
LLVM Clang from Source | MOOSE
mkdir llvm-build cd llvm-build cmake ../llvm -G 'Unix Makefiles' \ -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;compiler-rt;libcxx;libcxxabi;libunwind;openmp;lldb' \ -DCMAKE_INSTALL_PREFIX=/target/installation/path/llvm-19 \ -DCMAKE_INSTALL_RPATH:STRING=/target/installation/path/llvm-19/lib \ -DCMAKE_INSTALL_NAME_DIR:STRING=/target/installation/path/llvm-19/lib \ -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 \ -DLLVM_TARGETS_TO_BUILD="X86" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_MACOSX_RPATH:BOOL=OFF \ -DCMAKE_CXX_LINK_FLAGS="-L/some/path/to/gcc-13.3.1/lib64 -Wl,-rpath,/some/path/to/gcc-13.3.1/lib64" \ -DGCC_INSTALL_PREFIX=/some/path/to/gcc-13.3.1 \ -DCMAKE_CXX_COMPILER=/some/path/to/gcc-13.3.1/bin/g++ \ -DCMAKE_C_COMPILER=/some/path/to/gcc-13.3.1/bin/gcc
🌐
YouTube
youtube.com › watch
Build - LLVM clang 15.0.0 from source - YouTube
Build LLVM clang 15.0.0 from sourceKeywords: build, llvm, llvm-project, clang, clang++, clang-tidy, from source, cmake, make, linux, compiler, configuration,...
Published   November 28, 2022
🌐
GitHub
github.com › ziglang › zig › wiki › How-to-build-LLVM,-libclang,-and-liblld-from-source
How to build LLVM, libclang, and liblld from source
April 12, 2023 - Moved to Codeberg. Contribute to ziglang/zig development by creating an account on GitHub.
Author   ziglang
🌐
University of Texas
cs.utexas.edu › ~pingali › CS380C › 2019 › assignments › llvm-guide.html
Getting started with LLVM
LLVM uses CMake to generate a build system. You can specify the build system you want and the specified build system is later used to build the LLVM source files.
🌐
AMD ROCm
rocm.docs.amd.com › projects › llvm-project › en › latest › LLVM › llvm › html › GettingStarted.html
Getting Started with the LLVM System — LLVM 22.0.0git documentation
Stand-alone builds allow you to build a sub-project against a pre-built version of the clang or llvm libraries that is already present on your system. You can use the source code from a standard checkout of the llvm-project (as described above) to do stand-alone builds, but you may also build ...
🌐
GitHub
github.com › ARM-software › LLVM-embedded-toolchain-for-Arm › blob › main › docs › building-from-source.md
LLVM-embedded-toolchain-for-Arm/docs/building-from-source.md at main · ARM-software/LLVM-embedded-toolchain-for-Arm
$ apt-get install python3 git make ninja-build qemu $ apt-get install clang # If the Clang version installed by the package manager is older than 6.0.0, download a recent version from https://releases.llvm.org or build from source $ apt-get install cmake # If the CMake version installed by the package manager is too old, download a recent version from https://cmake.org/download and add it to PATH $ pip install meson
Author   ARM-software
🌐
Bernardnongpoh
bernardnongpoh.github.io › posts › llvm
Installing LLVM Compiler Infrastructure - Bernard Nongpoh
This blog walks you through how to install LLVM Compiler Infrastructure from scratch ... While building, your CPU might freeze; it better to close all programs before installation. We first need to clone the repository. To save space, we do a shallow clone. If you want the complete source code, go check this link Getting the source code and building LLVM Doing this will also pull llvm subprojects such as Clang and others.
🌐
GitHub
github.com › noloader › build-llvm
GitHub - noloader/build-llvm: Recipes to download and build LLVM, Clang front end and Compiler-RT from sources · GitHub
Recipes to download and build LLVM, Compiler front end and Compiler-RT from sources. The script builds the latest LLVM from release tarballs, which is currently version 7.0.
Author   noloader
🌐
WISESCIENCEWISE
wisesciencewise.wordpress.com › 2022 › 10 › 04 › build-llvm-from-source-on-ubuntu
Build LLVM from source on Ubuntu | WISESCIENCEWISE
October 4, 2022 - Get the llvm project files from its repository. > git clone https://github.com/llvm/llvm-project.git · Install the cmake. As cmake is used to build and configure the LLVM.
🌐
CompilerSutra
compilersutra.com › llvm tutorial - learn llvm step by step
Build LLVM from Source on Linux
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" ../llvm ... A common workflow uses CMake plus Ninja with a clean build directory and only the projects and targets you actually need. ... They build from source to experiment with compiler changes, test passes, study internals, or use newer LLVM versions than system packages provide.
🌐
Packtpub
subscription.packtpub.com › book › programming › 9781782166924 › 1 › ch01lvl1sec11 › building-from-sources
Building from sources
LLVM and Clang prebuilt packages ... compiled from the source otherwise. A beginner LLVM user must consider the fact that the basic setup for a LLVM-based compiler includes both LLVM and Clang libraries and tools. Therefore, all the instructions in this chapter are aimed at building and installing ...
🌐
LLVM
llvm.org › docs › Projects.html
Creating an LLVM Project — LLVM 23.0.0git documentation
You will simply need to find a way to use the source provided within that directory on your own. Typically, you will want to build your lib directory first followed by your tools directory. The LLVM build system provides a convenient way to build libraries and executables.