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

Producing a compile_commands.json #212

Closed
shanemikel opened this issue Jan 11, 2019 · 11 comments
Closed

Producing a compile_commands.json #212

shanemikel opened this issue Jan 11, 2019 · 11 comments

Comments

@shanemikel
Copy link

I'm wondering how I might use this system together with Bear (or producing the compile_commands.json file with CMake directly).

It's basically a file that tells where the includes for a project are so that IDEs and code editors can provide completion and other features.

@shanemikel
Copy link
Author

Usually I use hand written Makefiles, and the Bear tool is run like so:
# bear make -B

The -B flag forces a complete build, and the Bear program parses the output of Make to build a structured JSON file enumerating the included files for each output.

@floooh
Copy link
Owner

floooh commented Jan 12, 2019

Currently generation of the compile_commands.json file only happens when using one of the VSCode build configs (for similar reasons, so that VSCode can figure out the header search paths, defines etc..).

It's possible to get the same behaviour for other build configs via custom build configs by adding a cmake definition for CMAKE_EXPORT_COMPILE_COMMANDS=ON, but I'll just go ahead to always enable this... one sec...

@floooh
Copy link
Owner

floooh commented Jan 12, 2019

...ok, compile_commands.json is now always generated when running fips gen, the generated file is in fips_build/[project]/[config]/compile_commands.json.

@floooh floooh closed this as completed Jan 12, 2019
@floooh floooh reopened this Jan 14, 2019
@floooh
Copy link
Owner

floooh commented Jan 14, 2019

...wait there's a problem, CMAKE_EXPORT_COMPILE_COMMANDS is only implemented by the ninja and make generators:

https://cmake.org/cmake/help/v3.5/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

I need to add a fix back in which only sets the define when the ninja or make generator is used...

@floooh
Copy link
Owner

floooh commented Jan 14, 2019

Ok, fix is in 274d0ff

@floooh floooh closed this as completed Jan 14, 2019
@smokku
Copy link

smokku commented Nov 5, 2023

Why was this feature removed in 9512fb6 ?

@floooh
Copy link
Owner

floooh commented Nov 6, 2023

Hmm, probably fallout from the changes to write a CMakePresets.json, but not sure if this broke compile_commands.json or I thought that compile_commands.json would no longer be needed since IDEs use the CMakePresets.json file to figure out the information that's been written to compile_commands.json previously.

It may also be that having both a compile_commands.json and CMakePresets.json file confused the VSCode CMake Tools extension.

What's your use case for the compile_commands.json file?

@smokku
Copy link

smokku commented Nov 6, 2023

What's your use case for the compile_commands.json file?

I use clangd extension for context help and error detection.

image

It needs compile_commands.json to properly analyze the code.

@smokku
Copy link

smokku commented Nov 6, 2023

BTW, I am able to run ./fips config then [t] Toggle advanced mode and enable CMAKE_EXPORT_COMPILE_COMMANDS ON there.

But it would be nice if I would not have to. :-)

@floooh
Copy link
Owner

floooh commented Nov 8, 2023

FYI I reverted that change again in ae37991, so compile_commands.json is generated again. I only did some quick testing in VSCode on Mac and didn't see any problems, so either if there are problems, they are more subtle than what I'm currently seeing, or I really thought that the feature wasn't needed anymore when I removed it.

@smokku
Copy link

smokku commented Nov 8, 2023

Works fine! Thanks.

I just need to create .clangd config file in the root of my project, to point clangd to out-of-source compilation database dir and I'm done.

> cat .clangd

CompileFlags:
  CompilationDatabase: ../fips-build/tech42/linux-ninja-debug

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