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

How do I use compile_commands.json #6592

Closed
AverageComet250 opened this issue Nov 29, 2020 · 15 comments
Closed

How do I use compile_commands.json #6592

AverageComet250 opened this issue Nov 29, 2020 · 15 comments
Assignees
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state question

Comments

@AverageComet250
Copy link

So I've been looking into ultralight and uses the below to build a project

mkdir build
cd build
cmake ..
cmake --build . --config Release

I'm not fully sure what vscode does to build projects (and whether its this plugin or the cmake one that I need to change the settings for), but I know it isn't this. It seems I need a compile_commands.json file that I tell this plugin to use at the project level but I cant find documentation on this or anything showing the file format. I would appreciate it if someone could tell me how to use this file.

@michelleangela
Copy link
Collaborator

For the C++ Extension to use the compile_commands.json file, place its full file path into the c_cpp_properties.json file. This file is used to configure the C++ Extension IntelliSense. You can edit the file by running one of the two commands: C/C++: Edit Configurations (JSON) or C/C++: Edit Configurations (UI). If you are using the UI settings, the input field for compile_commands.json is under "Advanced Settings".

@michelleangela michelleangela added Feature: Configuration An issue related to configuring the extension or IntelliSense question labels Nov 30, 2020
@AverageComet250
Copy link
Author

AverageComet250 commented Nov 30, 2020

I know that but what do I actually put in the compile_commands.json file

@michelleangela
Copy link
Collaborator

michelleangela commented Nov 30, 2020

I know that but what do I actually put in the compile_commands.json file

The compile_commands.json file is generated by CMake and it is not usually modified for the C++ Extension to use, unless there is some special case or workaround that needs to be done. https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

@Colengms
Copy link
Collaborator

Colengms commented Dec 1, 2020

@AverageComet250 The format specifications for compile_commands.json can be found here: https://clang.llvm.org/docs/JSONCompilationDatabase.html

It would be possible to manually compose compile_commands.json. Though, unless individual files need to be configured differently, it would seem simpler to specify the same information in c_cpp_properties.json. Support for compile_commands.json is generally used to easily configure the extension if this file already exists as part of your build system.

@bobbrow
Copy link
Member

bobbrow commented Dec 1, 2020

If you are using CMake, then we recommend you install the CMake Tools extension. If you let that extension configure your project, you will not need compile_commands.json. If you have any trouble configuring it, open an issue here and we can help you out.

@AverageComet250
Copy link
Author

AverageComet250 commented Dec 1, 2020

I want to make it so that the build option runs

cmake .
cmake --build . --config Release

Instead of

cmake . or whatever the build button underneath the terminal or file does

Also I am using the cmake tools extension and my objective is to change what the build button on the bar at the bottom does

@Colengms
Copy link
Collaborator

Colengms commented Dec 1, 2020

Hi @AverageComet250 . With CMake Tools installed, you should see a text button at the bottom of the window that allows selection of build configuration type (Release, Debug, RelWithDebInfo, MinSizeRel), . Alternatively, you can use CMake: Select Variant command. With both a variant and a 'kit' selected, and a valid CMakeLists.txt file, run the CMake: Configure command to generate the build script. Then you should then be able to build your project using the CMake: Build command.

It sounds like you want to leverage a multi-config build, based on the command line you specified above (which passes in the variant at build time). Depending on the kit you've selected, CMake may or may not generate a 'multi-config' build. I don't believe CMake Tools exposes this (as some generators do not support multi-config). However, you can use CMake: Configure then CMake: Build to build based on whatever config is currently selected in the UI.

compile_commands.json should not contain invocation of CMake. Some CMake generators support creating a compile_commands.json when CMAKE_EXPORT_COMPILE_COMMANDS is specified.

@AverageComet250
Copy link
Author

I think my variant is Release and I'm using the x86_64 visual studio 2019 kit. I will test the cmake configure command and come back on whether that works.

Thanks

@sean-mcmanus sean-mcmanus added the more info needed The issue report is not actionable in its current state label Dec 4, 2020
@Colengms
Copy link
Collaborator

@AverageComet250 . Did my last response help you get this working? Or, if not, was there some part that did not work as described?

@AverageComet250
Copy link
Author

Sorry I'm still yet to do a proper test, though I can confirm that my variant is Debug and my kit is as specified in earlier post.

I'll come back after a proper test.

I closed it by accident by the way which is why I reopened it

@github-actions
Copy link

github-actions bot commented Mar 6, 2021

Hey @Colengms, this issue might need further attention.

@AverageComet250, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@AverageComet250
Copy link
Author

I'm gonna close this as I haven't actually tested it yet and I don't think I'm ever gonna need this. If someone could tell me how to modify what the build button does though, I'd really appreciate it

@sean-mcmanus
Copy link
Collaborator

@AverageComet250 What build button?

@AverageComet250
Copy link
Author

The one on the bar at the bottom, the one where you can select things like the python interpreter and other things

@sean-mcmanus
Copy link
Collaborator

Our extension doesn't provide that button so you'll need to ask the team (extension provider) that does. If you're referring to the CMake Tools build button you can use the "CMake: Set Build Target" command; otherwise, maybe there's another similar command you could look for.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state question
Projects
None yet
Development

No branches or pull requests

5 participants