Build clang, clang-tidy & co from source in 3.5 easy steps

You may find obsolete recipes even on the official llvm documentation. So here are up-to-date instructions, until they are not.

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build 
cd build
cmake -DCLANG_ENABLE_STATIC_ANALYZER=1 -DLLVM_ENABLE_ASSERTIONS=On DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=$HOME/local -DLLVM_ENABLE_LIBCXX=1 -DLLVM_ENABLE_PROJECTS="all" -G "Ninja" ../llvm
ninja install
ninja check-clang

That's it. Read ahead if you're interested by the details.

LLVM's subprojects used to be nested, now you should see all of them from the root of the repository:

clang  clang-tools-extra  compiler-rt  debuginfo-tests  libclc  libcxx  libcxxabi  libunwind  lld  lldb  llgo  llvm  openmp  parallel-libs  polly  pstl  README.md

The "llvm" entry isn't the root directory anymore, though still considered the source root. So, the path/to/llvm/source/root mentionned in the documentation would be ~/llvm-project/llvm and you would use this one even to simply build clang.

Those steps follow "get started" with the following touch:

  • RelWithDebInfo + Assertions rather than Debug.
  • Using ninja for faster build.
  • Using libc++, the llvm C++ Standard Library (project included in 'all')
  • Local install to ease experimentation.

The options are described here.

view raw install_llvm.md hosted with ❤ by GitHub

Comments