0

I have an existing cross-compilation build that uses Yocto and CMake. I've added:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

to CMakeLists.txt to generate compile_commands.json as part of my build. How can I tell VSCode's clang-tidy support to use this file? Can I do it without having to add the long path for the folder that Yocto and CMake put it into?

starball
  • 20,030
  • 7
  • 43
  • 238
parsley72
  • 8,449
  • 8
  • 65
  • 98

1 Answers1

1

Try putting the following in your workspace settings.json file:

"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true

The setting's description:

If true and compileCommands is set, the -p=<build-path> argument is passed to clang-tidy instead of build arguments being passed after --. This may not work if environment variables aren't set so that system includes can be found.

From the help message for clang-tidy's -p flag:

-p <build-path> is used to read a compile command database.

    For example, it can be a CMake build directory in which a file named
    compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    CMake option to get this output). When no build path is specified,
    a search for compile_commands.json will be attempted through all
    parent paths of the first input file . See:
    https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
    example of setting up Clang Tooling on a source tree.

Somewhat related GitHub issue ticket in the vscode-cpptools repo: C_Cpp.codeAnalysis.clangTidy.useBuildPath should not add "compile_commands.json" to the -p argument #9273

I'm not sure if that will just work for you. If it doesn't try specifying the -p flag and build path manually (the path to the directory containing the compile commands JSON file) using the "C_Cpp.codeAnalysis.clangTidy.args" VS Code setting.

starball
  • 20,030
  • 7
  • 43
  • 238