Can I automatically populate file c_cpp_properties.json from an existing Makefile?
For others trying to import makefiles, I have found a set of scripts that perform exactly what I wanted to achieve, the management of STM32 embedded projects through Visual Studio Code. If you dig into the scripts folder, you can find the make parser and the Visual Studio Code project files populator.
Here the repository. Enjoy!
This answer may not entirely give you what you want, but hopefully it helps you setting up your Visual Studio Code environment.
In your question title, you mention "Makefile projects", which is an indication that you have the wrong impression that (GNU) Makefiles capture project settings in a way similar to Visual Studio project files do. Makefiles do not work like that and the short answer to your question is no, there does not seem to be a way to "import" Makefiles into Visual Studio Code and have it automatically set values in your c_cpp_properties.json file.
Having said that, there are some other mechanisms that may help you getting started with Visual Studio Code in your situation, depending on the other elements you have in your toolchain.
Visual Studio Code works with the premise that it opens one or more directories in your file system. When you do so, it will automatically scan all its subdirectories, display the tree and do linting (if enabled) to detect problems. Indeed, include directories need to be added manually to your c_cpp_properties.json file, but to add all your subdirectories recursively to the list of include directories, you can use the expression
"${workspaceRoot}/**"
as one of the elements in your includePath
setting. See the blog post Visual Studio Code C/C++ extension May 2018 Update – IntelliSense configuration just got so much easier! for more details. That often resolves a lot of the missing symbols. If you are using external or third-party libraries as well, then you have to add those to your includePath
setting manually, there isn't any way around that.
Additionally, you can create Visual Studio Code Tasks to execute your make
command to your liking. This is explained here: Integrate with External Tools via Tasks. The Microsoft C/C++ Extension comes with a set of so-called problemMatchers that parse the output of your command and can interpret that for certain known compilers. You will see hyperlinks for errors and warning to navigate directly to the associated location in your code.
An example of such a Task may look like this:
{
"label": "Build All Debug",
"type": "shell",
"command": "make -f path/to/Makefile DEBUG=1",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$gcc"
]
}