How to install clang-tidy on macOS?

Michael Reneer picture Michael Reneer · Nov 2, 2018 · Viewed 12.7k times · Source

How do you install clang-tidy on macOS?

It seems quite easy to install clang-format (using brew) on macOS, but it it seems much harder to install clang-tidy without install and building all of clang and building from source. Is there a better option?

Answer

Michael Reneer picture Michael Reneer · Nov 19, 2018

I don't think there is a really easy way to do this today, here are some details:

  • clang comes installed on macOS and is the default compiler, but it does not come installed with clang-format or clang-tidy (or possibly any of the extra tools).
  • It's really easy to use brew to install clang-format if you want it: brew install clang-format
  • There is no clang-tidy brew formulae.

As a result it seems like the best way to get clang-tidy on macOS is to simply install all of llvm and then make symlinks for the tools you want to use.

brew install llvm
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"

Alternatively, you could download the prebuilt binaries and create the same symlinks. It's not a good idea to add all of llvm to your PATH because of conflicts with the default clang compiler.