How to build the latest clang-tidy?

I had same problem as Per Mildner. Got is solved with slightly modified code YvesgereY posted (I don't have enough reputation to post a comment to that answer, hence a new answer instead).

In short, I added -G "Unix Makefiles" to cmake. Without this option, no makefile will be generated. Also, I used -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;". It didn't work when just clang-tools-extra was specified.

Here is the whole snippet:

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build 
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;" ../llvm
make -j8 install-clang-tidy

Up-to-date steps:

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build 
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
make install clang-tidy

Reference, ninja, and other details: my own blog post.


EDIT: this answer is out of date — the LLVM project has moved to a single git repository at https://github.com/llvm/llvm-project. See answers below for updated instructions.


clang-tidy is intended to be built inside a checkout of llvm/clang, and depends on CMake macros from the llvm project. You should check out the llvm repo, then the clang repo inside llvm/tools/clang, then the clang-tools-extra repo inside llvm/tools/clang/tools/extra. Then you can run CMake on the top-level directory, and make clang-tidy should work.

If you're not interested in building it yourself, it looks like the Homebrew formula for LLVM also includes the extra tools: https://github.com/Homebrew/homebrew-core/blob/382d3defb5bc48ce2dccd17261be70c4ada9a124/Formula/llvm.rb#L181