How to add clang-tidy to open source project?

CMake currently has built in clang-tidy support via:

However, it only works on the Makefile / Ninja generator:

The Makefile Generators and the Ninja generator will run this tool along with the compiler and report a warning if the tool reports any problems.

Wouldn’t this cause workflow issues for Visual Studio / XCode users?

I work on a decently popular open source project and want to ensure a smooth workflow for as much developers as possible.

AFAIK, the VS and XCode buildsystems don’t support running arbitrary commands to compile a file, which is required to run clang-tidy. This is beyond our control. If someone can figure out an alternate method of supporting clang-tidy in these generators, that would be welcome.

For now, to support the widest range of users and the easiest setup, I’d recommend using Ninja. It’s supported on every platform that CMake supports, and is easy to install.

1 Like