Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of put a compile_commands.json at source root #218

Closed
playgithub opened this issue Aug 14, 2021 · 5 comments
Closed

Instead of put a compile_commands.json at source root #218

playgithub opened this issue Aug 14, 2021 · 5 comments

Comments

@playgithub
Copy link

For cmake projects, compile_commands.json has to be copied/linked to the source root directory now.
Instead of this, can a property of vscode workspace be set, so that vscode-clangd knows where is compile_commands.json?

@HighCommander4
Copy link
Contributor

Yes, this can be done today by adding the following to <project>/.vscode/settings.json:

{
  "clangd.arguments": [
    "--compile-commands-dir=<path_to_directory_containing_compile_commands.json>"
  ]
}

Another way is to use clangd's own config file (see the CompilationDatabase key in the docs).

@playgithub
Copy link
Author

Yes, this can be done today by adding the following to <project>/.vscode/settings.json:

{
  "clangd.arguments": [
    "--compile-commands-dir=<path_to_directory_containing_compile_commands.json>"
  ]
}

That's it, thanks.

Another way is to use clangd's own config file (see the CompilationDatabase key in the docs).

It doesn't seem workspace specific, does it?

@HighCommander4
Copy link
Contributor

Another way is to use clangd's own config file (see the CompilationDatabase key in the docs).

It doesn't seem workspace specific, does it?

It can be. From the docs:

  • project configuration: a file named .clangd in the source tree. (clangd searches in all parent directories of the active file).

@i-ky
Copy link

i-ky commented Aug 14, 2021

@playgithub, if you use CMake Tools extension, then there is a cmake.copyCompileCommands setting that tells CMake Tools to copy compilation database from build directory to a desired location (e.g. ${workspaceFolder}). This will work even if you have different build directories depending on build configuration and whatnot. --compile-commands-dir and CompilationDatabase will only allow one possible location.

@playgithub
Copy link
Author

@playgithub, if you use CMake Tools extension, then there is a cmake.copyCompileCommands setting that tells CMake Tools to copy compilation database from build directory to a desired location (e.g. ${workspaceFolder}). This will work even if you have different build directories depending on build configuration and whatnot. --compile-commands-dir and CompilationDatabase will only allow one possible location.

Anyway it's an assistant file, I prefer to make it transparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants