Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install clang-tidy on macOS?

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?

like image 407
Michael Reneer Avatar asked Nov 02 '18 00:11

Michael Reneer


People also ask

Where is clang-format on Mac?

If you have the llvm toolchain already installed, you can find the clang-format.py file in /usr/local/opt/llvm/share/clang/clang-format.py without having to install a separate clang-format binary through Homebrew.


1 Answers

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.

like image 50
Michael Reneer Avatar answered Sep 23 '22 16:09

Michael Reneer