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

[Bug] current working directory is not changed when using `CMake: Run Without Debugging`

Open Count-MHM opened this issue 6 months ago • 4 comments

Brief Issue Summary

When binaryDir is changed by changing Configuration Preset, or by using cmake.buildDirectory in settings.json file, CMake: Run Without Debugging (from status bar or via Command Palette) doesn't change directory of Cmake/Launch terminal.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.103.1",
  "cmtVersion": "1.21.36",
  "configurations": [
    {
      "folder": "e:\\DEV\\C++\\Projects\\vscode-cmake-wrong-directory",
      "cmakeVersion": "4.1.0",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {
        "C": "cl.exe",
        "CXX": "cl.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Release",
    "buildTypesSeen": [
      "Release"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "HelloWorld",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "always",
      "configureOnOpen": true
    }
  ]
}

Debug Log

[main] Building folder: E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release HelloWorld
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build HelloWorld
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release --config Release --target HelloWorld --
[proc]   with environment: ######################## N/A ########################
[build] ninja: no work to do.
[driver] Build completed: 00:00:00.048
[cmakefileapi-parser] Read reply folder: E:\DEV\C++\Projects\vscode-cmake-wrong-directory\build\Windows-MSVC-Release\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-f7a7b30d5606e31d8cbf.json","cmakeFiles-v1-fe9c08706dd55d49eb4d.json","codemodel-v2-376011dbf1f65144925d.json","directory-.-Release-d0094a50bb2071803777.json","index-2025-08-15T18-12-38-0913.json","target-HelloWorld-Release-ddab750cf9c9297d5e78.json","toolchains-v1-b72720c52195983157ee.json"]
[build] Build finished with exit code 0
[cache] Reading CMake cache file E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [7295] cmake.launchTarget finished (returned {"name":"CMake/Launch - HelloWorld","processId":{},"creationOptions":{"name":"CMake/Launch - HelloWorld","env":{"########################": "N/A ########################","CC":"cl.exe","CXX":"cl.exe","_CMAKE_TOOLS_LAUNCH_TERMINAL_TARGET_NAME":"HelloWorld","_CMAKE_TOOLS_LAUNCH_TERMINAL_PATH":"C:\\WINDOWS\\System32\\cmd.exe"},"cwd":"E:\\DEV\\C++\\Projects\\vscode-cmake-wrong-directory\\build\\Windows-MSVC-Debug"},"state":{"isInteractedWith":true,"shell":"cmd"},"dimensions":{"columns":175,"rows":20}})
[extension] [7730] cmake.logDiagnostics started
[extension] [7730] cmake.logDiagnostics finished (returned undefined)

Additional Information

Using a simple c++ program to print current path: Image Image

Steps to reproduce:

  1. vscode-cmake-wrong-directory.zip
  2. set preset to "GCC-Debug" run with status bar or via CMake: Run Without Debugging
  3. set preset to "GCC-Release" run with status bar or via CMake: Run Without Debugging
  4. set preset to "Clang-Debug" run with status bar or via CMake: Run Without Debugging
  5. set preset to "Clang-Release" run with status bar or via CMake: Run Without Debugging
  6. see that all are run inside GCC-Debug directory

Also, I noticed that changing compiler to or from MSVC resets CMake/launch terminal (probably to set up environment) and because of this reset changing compiler to or from MSVC doesn't cause this issue. (changing configuration while in MSVC still causes this issue though) Changing compiler between GCC and Clang causes this issue because terminal is not reset.

Count-MHM avatar Aug 15 '25 18:08 Count-MHM

@Count-MHM Thank you for your report. We tried to check this issue in the sample project. It seems that we reproduced this issue, but the results are slightly different from yours. Could you recheck this issue? if we missed anything, please let us know. Thank you.

Image

yanghhhhhhh avatar Aug 19 '25 09:08 yanghhhhhhh

@yanghhhhhhh Yes, that was what I'm experiencing. I'm not sure what you mean by differences, if you mean that gcc and clang runs are not being shown in the same terminal, it is because the GIF closes the terminal before running clang. If there is another difference that I missed please let me know.

Count-MHM avatar Aug 19 '25 09:08 Count-MHM

This is my reproduction with an empty VSCode profile with only ms-vscode.cpptools-extension-pack installed

https://github.com/user-attachments/assets/a62dd38d-acff-46f5-91eb-9d057d001e96

Count-MHM avatar Aug 19 '25 11:08 Count-MHM

@Count-MHM 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 it. (vscode-cmake-wrong-directory.zip)
  2. Open CMake pane, choose "GCC-Debug", press F1 and run command: "CMake: Run Without Debugging".
  3. Choose "GCC-Release", press F1 and run command: "CMake: Run Without Debugging".
  4. Choose "Clang-Debug", press F1 and run command: "CMake: Run Without Debugging".
  5. Choose "Clang-Release", press F1 and run command: "CMake: Run Without Debugging".
  6. Choose "MSVC-Debug", press F1 and run command: "CMake: Run Without Debugging".
  7. Choose "MSVC-Release", press F1 and run command: "CMake: Run Without Debugging".
  8. Observe the debug output, they all run inside GCC-Debug directory.

Details please see following video:

Image

FYI: @gcampbell-msft

yanghhhhhhh avatar Aug 20 '25 03:08 yanghhhhhhh