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

Deletes CMakeCache.txt on file save

Open ronniegeraghty opened this issue 1 year ago • 10 comments

Brief Issue Summary

When using VSCode for a C++ project where I use CMake and vcpkg, I run cmake .. from my build directory to configure my CMake build. Then I run cmake --build . to build my project. After this there is a CMakeCache.txt file in my build directory. Then I go to make a change to my main.cpp file and save it. After saving the changes, the CMakeCache.txt file is gone and trying to run the same cmake --build . to build my project returns the following:

Error: could not load cache

I also get the following pop up in VSCode: image

Disabling the extension did stop the problem.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.92.0",
  "cmtVersion": "1.18.44",
  "configurations": [
    {
      "folder": "c:\\Users\\rgeraghty\\Desktop\\AzureSample",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

I'm not using the command pallet build command. I'm just running the cmake build command in the terminal. 
I'd like to use the extension of the features it provides when writing my `CMakeLists.txt` file but want to trigger my build via the terminal.

Additional Information

No response

ronniegeraghty avatar Aug 08 '24 23:08 ronniegeraghty

@ronniegeraghty I created a project by myself, following your steps to make changes to the content in the main.cpp file after I build the project, the CMakeCache.txt file in my build folder doesn't disappear automatically, can you provide a simple project that can reproduce the problem so that it will be easier for us to investigate the issue, looking forward to receiving your reply!

v-frankwang avatar Aug 13 '24 10:08 v-frankwang

This is what I am seeing: CMakeToolsExtensionIssue

Maybe it's because I don't have the extension configured. I'm just using it for the syntax highlighting in the editor. I don't want to use the command pallet commands in this scenario.

ronniegeraghty avatar Aug 14 '24 01:08 ronniegeraghty

Here's a link to the project it's happening in, but there's not much in it beside a basic hello world C++ program and a basic CMakeLists.txt file. https://github.com/ronniegeraghty/azure-cpp-sample/tree/CMakeToolsExtensionIssue

ronniegeraghty avatar Aug 14 '24 01:08 ronniegeraghty

@v-frankwang, in your test did you also get the error pop up about the extension not being able to determine what CMake generator to use?

ronniegeraghty avatar Aug 14 '24 01:08 ronniegeraghty

@ronniegeraghty Thank you very much for your reply! I'm very sorry, I don't know why I can't double-click to open your recording, so I can't clearly see what's in the output window and I don't have access to open the project you provided. I can go ahead and create a simple project to reproduce your problem, can you provide a screenshot of the output window?

v-frankwang avatar Aug 14 '24 02:08 v-frankwang

@ronniegeraghty When I tried on a new virtual machine, I was able to reproduce this problem you mentioned by installing vscode directly without going to install anything else, and when I installed visual studio on the machine (Install the "Desktop development with C++ After installing visual studio on the machine (Install the "Desktop development with C++" workload) and using the Developer Command Prompt for VS to run the command code. to open vscode, and performing the steps to reproduce it again, the problem does not occur.

Actual result: 3969

v-frankwang avatar Aug 14 '24 07:08 v-frankwang

@ronniegeraghty We usually don't run into this problem in our tests because we open vscode the way I mentioned in the recording so that vscode can use the ninja generator and the C/C++ compiler installed in visual studio.

v-frankwang avatar Aug 14 '24 07:08 v-frankwang

@ronniegeraghty Does modifying the settings for when we automatically configure for you help the trouble you're facing?

cmake.automaticReconfigure cmake.configureOnEdit

gcampbell-msft avatar Aug 14 '24 09:08 gcampbell-msft

@ronniegeraghty Does modifying the settings for when we automatically configure for you help the trouble you're facing?

cmake.automaticReconfigure cmake.configureOnEdit

Turning the cmake.automaticReconfigure setting off did not change the behavior and neither did turning off cmake.configureOnEdit.

I'm not opening VSCode by running the code . command from any terminal. I'm opening it just by clicking the shortcut icon on my desktop.

Is this video more clear? https://github.com/user-attachments/assets/9c51ee8f-afc8-4b87-8491-3a9b47e0e1bc

I've also noticed it's removing the CMakeCache.txt file when I reload the VSCode Window.

Here's a screenshot of the error pop up: image

In my project I'm not specifying a specific generator to use. I'm letting CMake find the generator and C++ compiler which it's picking up from MSVC.

Again. In my scenario, I'm not interested in using the command pallet commands from the extension or driving my CMake processes through the editor. I want to do that using CMake terminal commands. I do want the syntax highlighting and auto complete for my CMake files the extension gives. And it seems strange to me that the extension would stop me from doing that.

ronniegeraghty avatar Aug 14 '24 19:08 ronniegeraghty

@ronniegeraghty Thank you very much for your reply, there is a similar issue regarding this issue that our developers are investigating & dealing with, I will update the comment under this issue of yours when this issue :https://github.com/microsoft/vscode-cmake-tools/issues/3834 is fixed.

v-frankwang avatar Aug 16 '24 09:08 v-frankwang

@ronniegeraghty This issue should be fixed in the most recent pre-release and we hope to do another official release this week. Thanks! I'll close this issue now that we have a version out there with the fix. Please let us know if there are any issues and create a new issue if there is something to be investigated. Thanks!

gcampbell-msft avatar Sep 03 '24 10:09 gcampbell-msft