3

I am trying to use clang-tidy for my project, using a .clang-tidy config file. IDE integration tool I used for clang-tidy is telling me that it can't find compile_commands.json file. I figured this is because I use out-of-source builds and I need to somehow encode this information on my .clang-tidy configuration. I was not able to find any pointers on documentation or online examples.

How do we specify the path to compile_commands.json file using the .clang-tidy configuration file?

meguli
  • 1,426
  • 1
  • 18
  • 35

2 Answers2

0

There is no difference whether you use .clang-tidy configuration file or not. When you invoke clang-tidy, the -p <build-path> option can be used to specify the directory that contains the compile_commands.json.

eerorika
  • 232,697
  • 12
  • 197
  • 326
  • But the thing is, I am trying to use an IDE plugin and I am interacting with that plugin only through a .clang-tidy file. As far as I can see from their documentation, I can't find a way to pass command line arguments to clang-tidy executable using this plugin. That's why I wanted to be able to put it inside .clang-tidy file where I placed the checks I wanted to enable. – meguli Mar 07 '22 at 09:57
  • @meguli Ideally, the IDE should know the dir where you build, so the plugin should provide the option automatically. If it doesn't do that, and doesn't let you specify the arguments, then it doesn't seem to be a very useful plugin. Maybe create a support ticket. (or write a better plugin of your own since you're a programmer ;) – eerorika Mar 07 '22 at 10:08
  • I am looking for answers on the plugin's slack community as well, just wanted to see if there might be a clang specific workaround. – meguli Mar 07 '22 at 10:28
  • As a workaround, you can create script file `clang-tidy.sh` that invokes tidy with build directory: e.g. `clang-tidy -p "$@"`. Point shell script as clang-tidy executable for the plugin. – R2RT Mar 07 '22 at 10:38
0

Not sure what IDE you are using, but for VSCode's plugin Clang-Tidy you can create a file .vscode/settings.json (if it does not exist) in root directory of your project and put the next lines

{
    "clang-tidy.buildPath":"build"
}

where "build" is your directory with compile_commands.json