Caphyon / clang-power-tools

Bringing clang-tidy magic to Visual Studio C++ developers.
http://www.clangpowertools.com
Apache License 2.0
472 stars 57 forks source link

clang-build.ps1 vcpkg include for compile_commands.json #1305

Closed IbrahimHindawi closed 11 months ago

IbrahimHindawi commented 11 months ago

Hello, Thanks for the awesome tool! I'm using clang-build.ps1 -export-json command line to generate compile_commands.json for neovim lsp and it works fine except that it doesn't detect vcpkg so I had to manually include the vcpkg path to the compile_commands.json: -I\"C:\devel\vcpkg\installed\x64-windows\include\" Can we please have an option to force it to include the vcpkg include path if vcpkg is present on the system? Thank you.

mariru27 commented 11 months ago

Hi @IbrahimHindawi,

Thank you for reporting this issue

I have tested this case and I found in compile_commands.json a relative path to the needed library. If you export compilation database from extension Clang Power Tools you will find the absolute path in output log Do you find a problem in using a relative path, or maybe you do not find any reference to your library in compile_commands.json?

Can you give us a test project to reproduce the problem?

Kind regards, Marina

IbrahimHindawi commented 11 months ago

@mariru27 Thank you for your reply.

Relative paths to libraries are not a problem, my only problem is the lack of inclusion of the absolute path to vcpkg's include directories: -I\"C:\devel\vcpkg\installed\x64-windows\include\" into the compile_commands.json. Maybe I missed it?

I am currently using Clang Power Tools script in this project: https://github.com/IbrahimHindawi/cgfx. I have made a workaround to add the absolute path of the vcpkg include directories to the compile_commands.json using this python script: https://github.com/IbrahimHindawi/cgfx/blob/main/scripts/finalize.py.

I only need that since NeoVim doesn't understand what vcpkg integrate install is like Visual Studio, so I have to force it to look in the vcpkg include dir. Let me know if you run into any issues executing the scripts\bbuild.bat command.

Best regards, Ibrahim

mariru27 commented 11 months ago

@IbrahimHindawi, thank you for giving detailed instructions on how to reproduce the problem

After testing this problem I will return to you with an updated status of this issue. (This will take some time, because we have some tasks to complete first)

Kind regards, Marina

IbrahimHindawi commented 11 months ago

@mariru27 No problem, I already have a temporary fix! Thank you very much. Here is some extra information just for clarification: Here is the Clang Power Tools json file output:

[
  {
    "directory": "C:/devel/cgfx/build",
    "command": "\"C:/Program Files/LLVM/bin/clang++.exe\" -x c \"C:/devel/cgfx/thirdparty/glad/src/glad.c\"  -fsyntax-only \"-D_MT\" \"-D_DLL\" \"-DWIN32\" \"-D_WINDOWS\" \"-DCMAKE_INTDIR=/\"Debug/\"\" \"-D_DEBUG_FUNCTIONAL_MACHINERY\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/atlmfc/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/include\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt\" -I\"C:/devel/cgfx/source\" -I\"C:/devel/cgfx/thirdparty/glad/include\" -I\"C:/devel/cgfx/thirdparty/stb/include\" -I\"C:/devel/cgfx/thirdparty/linmath/include\"",
    "file": "C:/devel/cgfx/thirdparty/glad/src/glad.c"
  }
  ,
  {
    "directory": "C:/devel/cgfx/build",
    "command": "\"C:/Program Files/LLVM/bin/clang++.exe\" -x c \"C:/devel/cgfx/source/main.c\"  -fsyntax-only \"-D_MT\" \"-D_DLL\" \"-DWIN32\" \"-D_WINDOWS\" \"-DCMAKE_INTDIR=/\"Debug/\"\" \"-D_DEBUG_FUNCTIONAL_MACHINERY\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/atlmfc/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/include\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt\" -I\"C:/devel/cgfx/source\" -I\"C:/devel/cgfx/thirdparty/glad/include\" -I\"C:/devel/cgfx/thirdparty/stb/include\" -I\"C:/devel/cgfx/thirdparty/linmath/include\"",
    "file": "C:/devel/cgfx/source/main.c"
  }
]

Here is the json file after my python script:

[
  {
    "directory": "C:/devel/cgfx/build",
    "command": "\"C:/Program Files/LLVM/bin/clang++.exe\" -x c \"C:/devel/cgfx/thirdparty/glad/src/glad.c\"  -fsyntax-only \"-D_MT\" \"-D_DLL\" \"-DWIN32\" \"-D_WINDOWS\" \"-DCMAKE_INTDIR=/\"Debug/\"\" \"-D_DEBUG_FUNCTIONAL_MACHINERY\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/atlmfc/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/include\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt\" -I\"C:/devel/cgfx/source\" -I\"C:/devel/cgfx/thirdparty/glad/include\" -I\"C:/devel/cgfx/thirdparty/stb/include\" -I\"C:/devel/cgfx/thirdparty/linmath/include\" -I\"C:/devel/vcpkg/installed/x64-windows/include\"",
    "file": "C:/devel/cgfx/thirdparty/glad/src/glad.c"
  }
  ,
  {
    "directory": "C:/devel/cgfx/build",
    "command": "\"C:/Program Files/LLVM/bin/clang++.exe\" -x c \"C:/devel/cgfx/source/main.c\"  -fsyntax-only \"-D_MT\" \"-D_DLL\" \"-DWIN32\" \"-D_WINDOWS\" \"-DCMAKE_INTDIR=/\"Debug/\"\" \"-D_DEBUG_FUNCTIONAL_MACHINERY\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/atlmfc/include\" -isystem\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/include\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt\" -I\"C:/devel/cgfx/source\" -I\"C:/devel/cgfx/thirdparty/glad/include\" -I\"C:/devel/cgfx/thirdparty/stb/include\" -I\"C:/devel/cgfx/thirdparty/linmath/include\" -I\"C:/devel/vcpkg/installed/x64-windows/include\"",
    "file": "C:/devel/cgfx/source/main.c"
  }
]

The only difference is the last include of the "command" item.

mariru27 commented 11 months ago

Hi @IbrahimHindawi,

Do you have Use Vcpkg active?

Go to Project (cgfx) -> Properties:

image

Kind regards, Marina

IbrahimHindawi commented 11 months ago

Thank you! Didn't know I had to activate that. Closing Issue.