How to set a custom clang-tidy exe for Visual Studio and CMake Project

Akshat Jain 20 Reputation points
2024-08-08T07:22:55.7133333+00:00

Hello,
I have my own custom clang-tidy executable and I'd like Visual Studio to use it when I run Code Analysis on my target or file.

However, I couldn't find any option to set this up in Visual Studio, even though I followed the article:
https://learn.microsoft.com/en-us/cpp/code-quality/clang-tidy?view=msvc-170#clang-tidy-tool-directory

But I didn't find any tool directory present there.

Because I have to write custom checks with integrated clang-tidy, so that's why I have to add custom path for my clang-tidy.exe

Can someone help?

Regards,
Akshat

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,448 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 33,806 Reputation points Microsoft External Staff
    2024-08-09T06:41:38.9866667+00:00

    Hello @Akshat Jain,

    Welcome to Microsoft Q&A forum.

    I double checked in the latest version of Visual Studio 2022(currently 17.10.5), it’s true that the Clang-Tidy Tool Directory property doesn’t exist there.

    User's image

    Previously(several years ago), Eli Fessler mentioned(Code analysis with clang-tidy in Visual Studio – Future work):

    The UI doesn’t currently support pointing Visual Studio to use a custom clang-tidy.exe, which may be desired in the case of using custom checks, but we’re exploring this as an option going forward.

    Probably, this option is still not available on release version of VS 2022. So, I checked the release notes of Preview version of Visual Studio 2022 here => Custom Clang-Tidy Executable

    You can now use a custom clang-tidy executable for all your projects. This lets you run clang tidy on individual projects with your own custom rules, without relying on the default clang-tidy executable.

    And tested locally, I can see that the Clang-Tidy Tool Directory option shows in the Preview version of Visual Studio 2022.

    User's image

    I think currently you have two choices, one is trying to use preview version of VS 2022, the other is waiting for this feature to be released in release version of VS 2022 and use it.

    Please feel free to let us know if you have any further concerns :)

    Happy coding!

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.