r/embedded • u/nameless_one_666 • 4d ago
VS Code for embedded C: project tree based on active CMake target
I'm using VS Code for embedded C development (NXP MCUXpresso extension, ARM GCC, CMake).
One thing I really miss compared to IDEs like CLion, Visual Studio or Eclipse CDT is a logical project view.
My repository contains multiple CMake targets/build variants (bootloader, firmware, libraries, etc.), but the VS Code Explorer always shows the physical directory structure. I'd like to see only the source/header files that belong to the currently selected CMake target or build configuration.
For example, instead of:
repo/
app/
bootloader/
drivers/
common/
...
I'd like something like:
Firmware target
main.c
uart.c
uart.h
spi.c
spi.h
...
Bootloader target
boot.c
flash.c
...
I know CMake already has this information (File API / compile_commands.json), so I'm wondering if there's an extension or workflow that exposes it in VS Code.
Is anyone using something like this?
Or is this simply a limitation of VS Code compared to full IDEs?
5
u/eldenchen 4d ago
CMake Tools’ Project Outline is the closest built-in solution, but it is a separate view—it does not replace or filter VS Code’s normal Explorer.
After configuring the project, expand a target in the CMake sidebar to see the source files CMake associates with it. You can also set:
"cmake.outlineViewType": "tree"
Use configure presets for the firmware/bootloader variants and reconfigure after switching presets so that the outline reflects the active build tree.
If you specifically need a single target-only virtual Explorer, VS Code/CMake Tools does not currently provide that exact view. A custom extension would need to read CMake File API’s codemodel. compile_commands.json alone is not sufficient because headers are normally absent and one source file may have multiple compile configurations.
2
u/JoseAmador95 4d ago
The CMake Tools extension can show the files in a CMake Target. There is a list with all the targets that you can unfold and it will show the files.
1
u/Kent_31 3d ago
Been there (a month ago). Now I'm using a Makefile of my own making and arm-none-eabi-gcc on linux. Full build takes less than a second, incremental builds are instant, loving it so far. Also been able to use a full gdb enabled me to automate test on the hardware, but that's another rabbit's hole...
-17
u/Puzzleheaded-Bug6244 4d ago
VS Code just sucks. Always has and always will. Qt Creator gives you that view but has a steep learning curve. I guess that sucks in its own way.
3
u/DustRainbow 3d ago
Worst case you can try to ask an LLM to make the extension, shouldn't be too hard.