xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

compile commands for headers in compile_commands.json #5418

Closed SnowinterCat closed 3 months ago

SnowinterCat commented 3 months ago

Is your feature request related to a problem? Please describe.

When I use clangd as a analyzer, I find that the source files are analyzed properly. But unfortunately, the header files are all reporting errors inside the header files. I looked up the documentation related to clangd and learned that it is the lack of a header file compilation method in the compile_command that prevents clangd from analyzing it. But it's true that normal header files don't need to be compiled, only qt projects need to compile header files.So the qt header in QtCreator works fine with clangd, because QtCreater generates the compile command for its header files. Is there any way to add a rules so that normal header files also generate a compile command, like QtCreater does for its header files?

Describe the solution you'd like

Perhaps we could add a rule that allows header files to be put into add_files, generating compile_commands, but not using the compiler to compile them. Or maybe modify this rule: "plugin.compile_commands.autoupdate". Add a parameter to it to support generating compile_commands for header files?

Describe alternatives you've considered

No response

Additional context

No response

SnowinterCat commented 3 months ago

I've found the reason, it's because clangd in llvm version 18.1.8 doesn't support -std:c++latest yet, it has nothing to do with the compile command. When I use c++20, clangd is able to analyze the header files properly.