You can use clang-tidy in visual studio now apparently. I really don’t like the cmake setting json they have, so I don’t want to use that to use clang-tidy, I prefer the old fashioned way. Would be nice if cmake would apply CMAKE_CXX_CLANG_TIDY to visual studio project generation.
Switching to clang-tidy for code analysis adds something like this to a vcxproj
CMAKE_CXX_CLANG_TIDY takes the path to the clang-tidy tool and optionally arguments for it. That is too low-level to map directly to the .vcxproj settings you describe. We’ll likely need some higher-level interface for it.
Clang-Tidy configuration
You can configure the checks that clang-tidy runs inside Visual Studio via the Clang-Tidy Checks option.
This input is provided to the --checks argument of the tool.
Any further configuration can be included in custom .clang-tidy files.
For more information, see the Clang-Tidy documentation on LLVM.org.
Ok, I also tested it in my project but I did not have clang-tidy installed with Visual Studio. Instead, I added another property VS_GLOBAL_ClangTidyToolExe and set it to “${CLANG_TIDY_EXECUTABLE}” which I previously searched with find_program. I make it easier for my users by searching in the default install location of LLVM windows installer:
ENV ProgramFiles
and
ENV ProgramFiles(x86
with PATH_SUFFIXES set to LLVM/bin.
This way, users/developers only have to flip a switch instead of lots of typing.
Thanks for the inspiration.
On trying it out:
Hell, this is slow! I like the direct integration into the editor like in QtCreator much better. Additionally, aborting a build does not abort the clang-tidy program.
It is crazy slow. I went ahead and turned off VS_GLOBAL_RunCodeAnalysis in my project. I also left VS_GLOBAL_EnableMicrosoftCodeAnalysis off, so clang tidy only. I’ll just run it once in a while manually. With the rest of the settings, “Analyze->Run code Analysis” runs clang-tidy manually. Once I have continuous integration going on this project, I’ll set it up to run there too. But too slow to run on a normal local build.