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

unxpected -I in compile_command.json #3020

Closed
garfieldkwong opened this issue Nov 4, 2022 · 7 comments
Closed

unxpected -I in compile_command.json #3020

garfieldkwong opened this issue Nov 4, 2022 · 7 comments
Milestone

Comments

@garfieldkwong
Copy link

Xmake Version

v2.7.2+202210241457

Operating System Version and Architecture

Ubuntu 22.04

Describe Bug

xmake use the flag -isystem for the package include path. But when generating the compile_command.json, it is -I

/usr/bin/clang-15 -c -Qunused-arguments -m64 -g -Wall -Wextra -Werror -O0 -std=c++2b -isystem <boost-path>/include -o build/.objs/y/linux/x86_64/debug/src/main.cpp.o src/main.cpp

compile_command.json:

{
  "directory": "<home-path>",
  "arguments": ["/usr/bin/clang-15", "-c", "-Qunused-arguments", "-m64", "-g", "-Wall", "-Wextra", "-Werror", "-O0", "-std=c++2b", "-I", "<boost-path>/include", "-o", "build/.objs/y/linux/x86_64/debug/src/main.cpp.o", "src/main.cpp"],
  "file": "src/main.cpp"
},

Expected Behavior

should generate the following in compile_command.json

{
  "directory": "<home-path>",
  "arguments": ["/usr/bin/clang-15", "-c", "-Qunused-arguments", "-m64", "-g", "-Wall", "-Wextra", "-Werror", "-O0", "-std=c++2b", "-isystem", "<boost-path>/include", "-o", "build/.objs/y/linux/x86_64/debug/src/main.cpp.o", "src/main.cpp"],
  "file": "src/main.cpp"
},

Project Configuration

No response

Additional Information and Error Logs

No response

@waruqi
Copy link
Member

waruqi commented Nov 4, 2022

I remember previous feedback from users that cpptools or clangd did not yet support parsing headers from -isystem, so xmake uses -I to provide better compatibility.

Also, "-I", "/xx" are valid arguments and the LSP should support it. If they don't support it, you should go to clangd or cpptools and give feedback on the problem.

@waruqi waruqi removed the bug label Nov 4, 2022
@garfieldkwong
Copy link
Author

I remember previous feedback from users that cpptools or clangd did not yet support parsing headers from -isystem, so xmake uses -I to provide better compatibility.

Also, "-I", "/xx" are valid arguments and the LSP should support it. If they don't support it, you should go to clangd or cpptools and give feedback on the problem.

So could we have an argument to adjust it?

@garfieldkwong
Copy link
Author

And according to https://clangd.llvm.org/guides/system-headers#search-directories-mentioned-with-compile-flags, clangd does support "-isystem"

and by my testings, when I replace all "-I" with "-isystem" in compile_commands.json, both clangd and clang-tidy respect the "-isystem" in compile_commands.json

@waruqi
Copy link
Member

waruqi commented Nov 4, 2022

Not only clangd, but also many LSPs, cpptools/ccls ... There is no guarantee that all LSPs will support -isystem, but -I is certainly the most compatible.

@garfieldkwong
Copy link
Author

So could we have an argument to adjust it? Since -isystem will ignore the warning and tidy error but -I will still have it.

@waruqi
Copy link
Member

waruqi commented Nov 4, 2022

no arguments now.

@waruqi
Copy link
Member

waruqi commented Dec 29, 2022

I added a --lsp=clangd argument to improve it for clangd.

xmake project -k compile_commands --lsp=clangd

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

2 participants