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

[Bug] Multi-root workspace does not use "active folder" for build task

Open elrosch opened this issue 5 months ago • 6 comments

Brief Issue Summary

Using Version 1.21.36

When using the following entry in tasks.json of the workspace root.

        {
            "label": "Build ",
            "command": "build",
            "type": "cmake",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },

CMake always tries to build the build command in workspace root (i.e the first entry of the available configurations) instead of the current active folder. This behavior seems to have changed in one of the recent versions. It actually used to work.

Also providing "options" : { "cwd": ... does not change that behavior.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.102.0",
  "cmtVersion": "1.21.36",
}

Debug Log

.

Additional Information

No response

elrosch avatar Jul 11 '25 13:07 elrosch

@elrosch Does this reproduce with the previous official version of the extension?

gcampbell-msft avatar Jul 11 '25 15:07 gcampbell-msft

@gcampbell-msft I just tried with the previous version (v1.20.53) and the issue does not reproduce with that version. Seems like it has been introduced with the recent version (v1.21.36).

elrosch avatar Jul 14 '25 05:07 elrosch

I am experiencing the same issue.

hwmaier avatar Aug 07 '25 08:08 hwmaier

@elrosch @hwmaier Thank you for your report. We tried to reproduce this issue in our side. Could you please check this video and see if it is the same as yours? If we missed something, please let us know. In order for us to investigate further, could you provide us with a sample project? Thank you.

https://github.com/user-attachments/assets/02d49c42-4371-4cbb-b2bd-7073d3ad3a28

yanghhhhhhh avatar Aug 08 '25 07:08 yanghhhhhhh

I have been using the Active Folder for quite some time to build my projects which since the latest version seems broken.

Image

I am using the Active Folder feature with multiple source folders which can be selected using the menu. For simplicity only two are shown here:

"cmake.sourceDirectory": [
    "${workspaceFolder}/apps/blinky",  // first entry which is wrongly selected by the build command
    "${workspaceFolder}/apps/hello_world"  // <- "active folder"
],

I am using this entry in tasks to run the the build with Cmake Tools built in command:

    "tasks": [
        {
            "label": "cmake --build",
            "type": "cmake",
            "command": "build",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            ]

The CMake configure preset is ek_ra8m1 in this example and the CMake build preset is not set and left at default.

This is the build output when Active Folder is set to hello_world using previous version 1.20.53

Workspace is /C:/Users/henrik/Projects/devel/zephyr4
build task started....
"c:\Program Files\CMake\bin\cmake.EXE" --build C:/Users/hm/Projects/devel/zephyr4/apps/hello_world/build/ek_ra8m1 --
ninja: no work to do.
build finished successfully.

This is the build output when Active Folder is set to hello_world using version 1.21.36 , the active folder is not taken into account correctly and is set to the first entry of the cmake.sourceDirectory array (blinky) rather the active one (hello_world).

Workspace is /C:/Users/henrik/Projects/devel/zephyr4
build task started....
"c:\Program Files\CMake\bin\cmake.EXE" --build C:/Users/hm/Projects/devel/zephyr4/apps/blinky/build/ek_ra8m1 --
ninja: no work to do.
build finished successfully.

As a result the wrong project is built.

Interestingly enough if I change my task configuration to

    "tasks": [
        {
            "label": "cmake --build",
            "type": "shell",
            "command": "${command:cmake.tasksBuildCommand}",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            ]

then all works correctly.

So the issue seems to be with the built in cmake command.

hwmaier avatar Aug 08 '25 08:08 hwmaier

Hi , thanks for reporting issue here! Reproduced this issue on CMake Tools v1.21.36 release version. Repro Steps: 1. Download the attached project and open folder with it. (Workspace.zip) 2. Press F1, enter and select the command “Preferences: Open Settings (UI)”, type "cmake: Status Bar Visibility", choose "visible" 3. Select 'ProjectA' as active folder, run "CMake: Configure" > "Tasks: Run Task", observe the result. It built the ProjectA project. 4. Select 'ProjectB' as active folder, run "CMake: Configure" > "Tasks: Run Task", observe the result. It still built the ProjectA project.

This issue is not reproduced on CMake Tools v1.20.53.

Details please see following video:

https://github.com/user-attachments/assets/78ee0c4b-d201-4f94-a385-eeb3b2f80de2

FYI: @gcampbell-msft

yanghhhhhhh avatar Aug 11 '25 09:08 yanghhhhhhh