cancel
Showing results for 
Search instead for 
Did you mean: 

"CMake build" extension fails when files are in a sub-folder

ankes
Associate III

Hi,

The new STM32Cube for Visual Studio Code looks really nice but it suffers from (at least one) serious flaw: it does not work correctly when the target project is in a sub-folder.

This means every "multi-project repository" in the world just flat out doesn't work. Especially mine, where the repository contains not only the schematic but also the firmware and a GUI application.

I have attached a sample ZIP to this post which exhibits the issue. Extract both subfolders to a blank directory

  • If you open "advanced-sample-cmake" from the root, everything works
  • If you open "Subfolder" from the root then everything falls apart

Irony is that "Subfolder" contains the exactly same files than the other. The "STM32Cube CMake build" extension says "Could not configure code indexing until an active project is set" and stops right there.

Note that I can (somewhat) work around this issue by cloning my repository and then opening the subfolder in VS Code:

  • The "git" extension really does not like this, and suggests opening the parent directory instead
  • Git submodules do not work when I do this
  • Git change history does not work either
15 REPLIES 15
Pavel A.
Super User

What is surprising here? Git does not support files outside of the repository subtree. On the other hand Cmake supports subdirectories (CMakeLists.txt with add_subdirectory statements) 

 

 

ankes
Associate III

This post is about the "STMCube CMake Support" extension. Not git or CMake. Sorry for being unclear.

If I open the "advanced-sample-cmake" folder from the zip, I see this in the extension's debug output:

2025-11-06 22:42:31.773 [Info]  Adding cube-cmake path to environment: c:/Users/antti/.vscode/extensions/stmicroelectronics.stm32cube-ide-build-cmake-1.42.2/resources/cube-cmake/win32
2025-11-06 22:42:34.279 [Info]  Activating STM32Cube configurations for the code indexing feature...
2025-11-06 22:42:34.290 [Info]  Configuring code indexing for 'e:/advanced-sample-cmake'
2025-11-06 22:42:34.341 [Info]  Build folder is E:/advanced-sample-cmake/build/Debug
2025-11-06 22:42:34.345 [Info]  Updating .clangd configuration file (e:/advanced-sample-cmake/.clangd)
2025-11-06 22:42:34.355 [Info]  Updating c/cpp configuration file (e:/advanced-sample-cmake/.vscode/c_cpp_properties.json)
2025-11-06 22:42:34.359 [Info]  Watching for E:/advanced-sample-cmake/build/Debug/compile_commands.json changes...
And if I open "Subfolder", this is what I get instead:
2025-11-06 22:38:57.036 [Info]  Adding cube-cmake path to environment: c:/Users/antti/.vscode/extensions/stmicroelectronics.stm32cube-ide-build-cmake-1.42.2/resources/cube-cmake/win32
2025-11-06 22:38:58.111 [Info]  Activating STM32Cube configurations for the code indexing feature...
2025-11-06 22:38:58.147 [Info]  Configuring code indexing for 'e:/Subfolder'
2025-11-06 22:38:58.149 [Warn]  Could not configure code indexing until an active project is set

 

 

jacobwhite77888
Associate

Yeah, that’s definitely a frustrating issue especially for anyone who structures their projects with multiple subfolders. It sounds like STM32Cube for VS Code isn’t handling relative paths or project discovery correctly when the workspace isn’t at the root level. I’ve run into similar problems with other extensions that assume a flat project layout. The workaround you mentioned makes sense, but as you said, it breaks Git integration and history, which is far from ideal. Hopefully, ST will address this in an upcoming update, since multi-project repositories are pretty common, and having to restructure everything just to make the extension happy isn’t practical.

vincent_grenet
ST Employee

Dear community members,
Thank you for reporting and sharing all this valuable information.

I confirm that we are working on multi-project repositories, which raises many questions and options to find the best approach. I would greatly appreciate hearing your wishes and local practices here.

Based on your previous comments, if it’s not possible to share a full project, could you please share a schematic of your project structure? Mainly, highlight the folder organization and where the CMakeLists.txt files are located. Also, please explain how you add this project structure into VSCode (e.g., do you add the top-level folder to the workspace or rely on multiple folders added separately, creating a multi-root workspace?).

Thank you in advance. Your input will help us support you better!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
ankes
Associate III

I have published to my own repository several examples which likely exhibit the most common project patterns. When cloning any of the repositories linked in this post, include the submodules. Especially the "tinyusb" submodule contains a lot of CMakeLists.txt files which will easily confuse any autodetection mechanisms. CMake Tools extension is smart enough to ask which one it should use.

The https://github.com/anttikes/usb-fm-radio/tree/cmake-test branch presents what I consider likely to be the most common approach. Each subfolder holds its own project, and they are independent of each other. Switching between them in VSCode happens by manually adjusting the "cmake.sourcesDirectory" setting.

Note that the "GUI" subfolder is not present yet in the repo since I have not progressed this far. If I had, it would be there, and it would contain a CMakeLists.txt of its own.

In this branch, the STM32CubeIDE extension itself does not work correctly. It just says "Could not configure code indexing until active project is set", and things like "Setup STM32Cube project(s)" are grayed out. CLangd file is not generated or maintained, and overall the experience is rather poor. I believe that if the ST's extension were to follow "cmake.sourcesDirectory" then things would be much, much better.

The https://github.com/anttikes/usb-fm-radio/tree/cmake-test-in-root branch presents yet another example.

In this approach, the root folder of the repository contains a CMakeLists.txt file which then adds the "firmware" and the still-missing "GUI" subfolders, using CMake's own semantics. In this repository, the STM32CubeIDE extension works correctly, and maintains the CLangd file as expected. However, if I were to run the STM32CubeMX's code generation on the IOC file then things would break down. Horribly.

I believe this second approach is not that viable, mainly due to the fact that if "GUI" were to have submodules those modules would be defined at the root of the repository, and be kind-of shared between two independent disciplines.

I hope these two examples will shed some light on how I would see this extension used. In my opinion, the first example is likely the most prevalent, with independent projects all around, and manually adjusting the "cmake.sourcesDirectory" to choose which project you want to work on. The second approach can also be considered, and might be used in scenarios where a developer needs to build the entire thing in one go, and switch between debugging the firmware, and debugging a GUI application quickly. A ".vscode" folder with a suitable "launch.json" would definitively do the trick.

I have not included the third imaginable option which is the VS Code's "workspaces" approach. In this approach, there'd be a "workspace file" in the root folder of the repository, which would then include "Firmware" and "GUI" as kind-of independent projects. I believe this approach would not work for me since the "submodules" of the Firmware project are listed in the root of the repository, and if "GUI" were to have submodules of its own things would get very, very messy.

Also, one final point: neither the extension, nor STM32CubeIDE itself works correctly when HAL, CMSIS etc are provided via submodules. You can build the projects, sure, but any code generation will royally mess things up. Maybe allowing the developer to specify which folder contains the HAL or CMSIS headers is required?

@ankes Thanks for sharing but not sure fully get all your points here.
Cloning https://github.com/anttikes/usb-fm-radio/tree/cmake-test works for me. I'm able to build your project.

Cartu38OpenDev_0-1762717086981.png

Only 2 notes:

  • I'd to hack a bit your CmakeLists.txt to get it portable
    Cartu38OpenDev_1-1762717160467.png
  • I've added "Firmware" folder to VSCode workspace (not your git repo root because not CMakelists.txt at root of)
    Cartu38OpenDev_2-1762717248650.png

Doing all such I'm build success and prior STM32CubeiDE for Visual Studio Code is able to act as expected.
As example project setup is available

Cartu38OpenDev_3-1762717363896.png

I'll look at your second sharing https://github.com/anttikes/usb-fm-radio/tree/cmake-test-in-root

ankes
Associate III

Thanks for checking it out, @Cartu38 OpenDev.

Like explained, "cmake-test" branch is a scenario where the two projects, "Firmware" and the-still-unexisting "GUI" are independent in the sense that the developer would use VS Code's "CMake: Select Active Folder" command to change between the two. I provided it as a courtesy to @vincent_grenet in hopes that it might help them in choosing how to develop the extension further.

The key point of my entire post is to point out that the STM32Cube extension itself does not properly support a scenario where such "independence" exists. I am aware that declaring a VS Code workspace would solve the matter. Also, like shown in "cmake-test-in-root" (and also currently in "main") it is possible to utilize an alternative approach to make the extension work.

The punchline is if you need to create a workspace or fiddle with file locations in order to make an extension work then the extension obviously has a problem.

@ankes
Ok about  "Firmware" and the-still-unexisting "GUI" what I'm unable to catch is: what is issue to rely on multi workspace roots as you confirm this will work ?

Cartu38 OpenDev
Lead III

@ankes 
Looking at https://github.com/anttikes/usb-fm-radio/tree/cmake-test-in-root ok I got it. Very same than https://github.com/anttikes/usb-fm-radio/tree/cmake-test  adding as extra a top most CMakeLists.txt file.
Sounds like you intention is more to get a single project despite the 2 sub projects - if we may call them like this - may be independent. I guess it helps you to get CMake Tools usage easier allowing to build them all at once.
Right the stuff breaks because duplicate sub directory references but no MX fault, just you cannot concatenate these two independent projects without a bit of minor updates. The same doing this I'm able to build success.

Managing commonalities between your 2 projects Thanks git submodules or ... is too according to me your duty. I'm thinking we cannot ask anything to ST here. Each end user as its own taste / way or working.

Feel free to comment I like this topic kind, looking myself for best way to deal with code reuse, project structure.