vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

invalid compile_commands.json output

Open el-robo opened this issue 8 years ago • 1 comments

Brief Issue Summary

The compile_commands.json output generated by the cmake-tools extension is not properly formatted and leads to errors when used in the c/c++ extension.

Expected:

As read in the documentation, I would expect to be able to use the compile_commands.json file in the c/c++ extension so that intellisense would have the include paths.

Apparent Behavior:

The output of compile_commands contains all the data but cannot be parsed as valid json.

The output is structured as follows:

[ { "directory": "C:/code/davedeltacast/build", "command": "C:\PROGRA~2\MICROS~1.0\VC\bin\amd64\cl.exe @<< /nologo /TP -DNOMINMAX -DVIDEOMASTERHD_SDK_VERSION=6000000 -DWIN32 -IC:\code\davedeltacast\build\ba\version /DWIN32 /D_WINDOWS /GR /EHsc /W4 /MP /MDd /Zi /Ob0 /Od /RTC1 /FoCMakeFiles\ba_pre_install_hook.dir\ba\prereq_hook.cpp.obj /FdCMakeFiles\ba_pre_install_hook.dir\ /FS -c C:\code\davedeltacast\build\ba\prereq_hook.cpp <<", "file": "C:/code/davedeltacast/build/ba/prereq_hook.cpp" } ... more files ... ]

Please note that the "command" value is spread across three lines, with @<< as the end of the first, then the command arguments. And then <<", as the third.

When I edit the contents of compile_commands.json to be:

[ { "directory": "C:/code/davedeltacast/build", "command": "C:/PROGRA~2/MICROS~1.0/VC/bin/amd64/cl.exe /nologo /TP -DNOMINMAX -DVIDEOMASTERHD_SDK_VERSION=6000000 -DWIN32 -IC:/code/davedeltacast/build/ba/version -IC:/code/davedeltacast/include -IC:/ba/dave/094194/vs_14_x64/deb/install/include/Dave3 -IC:/ba/davesoftclock/688b34/vs_14_x64/deb/install/include /DWIN32 /D_WINDOWS /GR /EHsc /W4 /MP /MDd /Zi /Ob0 /Od /RTC1 /FoCMakeFiles/ba_pre_install_hook.dir/ba/prereq_hook.cpp.obj /FdCMakeFiles/ba_pre_install_hook.dir/ /FS -c C:/code/davedeltacast/build/ba/prereq_hook.cpp", "file": "C:/code/davedeltacast/build/ba/prereq_hook.cpp" } ... etc ... ]

The c/c++ extension can parse the contents of the file without issue. For this to work I replaced \ with / and joined the command key and value to be on a single line, removing the @<< and << bits.

Platform and Versions

[[For issues, fill out the following. Otherwise delete this section.]]

  • Operating System: Windows 7
  • CMake Version: 3.11.1
  • VSCode Version: 1.23.1
  • CMake Tools Extension Version: 0.11.1
  • Compiler/Toolchain: Visual C++ 14.0

Other Notes/Information

Perhaps it might be interesting to see my kits file as well: [ { "name": "MSVC 64bit", "compilers": { "CXX": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe", "CC": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe" } }, { "name": "MSVC 32bit", "compilers": { "CXX": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe", "CC": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" } } ]

el-robo avatar May 17 '18 08:05 el-robo

And right after writing this I see that cmake is the one who writes this file and not the extension... my bad.

el-robo avatar May 17 '18 09:05 el-robo