microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.48k stars 455 forks source link

1.19.49 Deletes Cache on Folder Open #4018

Closed DanKing-dev closed 2 months ago

DanKing-dev commented 2 months ago

Brief Issue Summary

In Visual Studio Code, on opening a folder, the CMakeCache.txt file is summarily deleted.

I am using a cross-compiler and this behavior immediately breaks my ability to build my projects.

This did not happen in the previous version.

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -E capabilities
[kit] Successfully loaded 7 kits from C:\Users\Foo\AppData\Local\CMakeTools\cmake-tools-kits.json
[variant] Loaded new set of variants
[cmakefileapi-driver] Removing c:/Users/Foo/project/code/build/CMakeCache.txt

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

gcampbell-msft commented 2 months ago

This is likely due to the cmake.configureOnOpen setting being set to true. Therefore, the extension should be configuring on open. If this is something you don't want, please change the cmake.configureOnOpen setting. Please let us know if this solves your issue, and if not, please provide a repro project, thanks!

the-programmer commented 2 months ago

It seems I have a similar issue. In version v1.18.44 everything was fine and in C1.19.49 somehow the Visual studio C compiler is selected (instead of my cross-compile chain).

I have cmake.configureOnOpen set to true, however with v1.18.44 this doesn't give any issues.

The startup log at v1.18.44

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -E capabilities
[variant] Loaded new set of variants
[main] Configuring project: [...] 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Wno-dev -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --no-warn-unused-cli -SC:/Development/[...] -Bc:/Development/[...]/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 12.3.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/12.3 rel1/bin/arm-none-eabi-gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (1.3s)
[cmake] -- Generating done (0.2s)
[cmake] -- Build files have been written to: C:/Development/[...]/build

And the startup log with v1.19.49

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -E capabilities
[variant] Loaded new set of variants
[cmakefileapi-driver] Removing c:/Development/[...]/build/CMakeCache.txt
[main] Configuring project: [...] 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Wno-dev -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --no-warn-unused-cli -SC:/Development/[...] -Bc:/Development/[...]/build
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Building for: Visual Studio 17 2022
[cmake] -- The C compiler identification is MSVC 19.40.33813.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (13.7s)
[cmake] -- Generating done (0.3s)
[cmake] -- Build files have been written to: C:/Development/[...]/build

Yes, I have installed Visual studio 17. As a test I also renamed C:\Users\[...]\AppData\Local\CMakeTools\cmake-tools-kits.json (since that is normally used to detect the installed kits). However on version 1.19.49 this has no effect.

gcampbell-msft commented 2 months ago

@the-programmer @DanKing-dev This is expected, the cmake.configureOnOpen is defaulted to true so it will automatically reconfigure when you open your project to ensure that everything is up to date. If you don't want this, you can simply turn that setting off. Thanks!

I'll close this issue since it's expected and controllable by a setting. Thanks for posting it!

the-programmer commented 2 months ago

I'm sorry but setting cmake.configureOnOpen to false didn't fix the underlying issue.

Now I have to press "Clean Reconfigure All Projects" in order to trigger the issue. (Shall I make a new issue for this?)

gcampbell-msft commented 2 months ago

@the-programmer I'm not sure I'm understanding your issue. Running Clean Reconfigure All Projects means that it will certainly delete the files and reconfigure, this is expected behavior.

Is there something I'm misunderstanding about your expectations here?

the-programmer commented 2 months ago

Hi @gcampbell-msft, yes there seems to be different issues in play.

As seen in my first comment, cmake tools 1.19 seems to select a different compiler than with 1.18. On both versions the cmakefile is the same.

Note that I and @DanKing-dev are both cross compiling.

So a better title would be "cmake tools selects on 1.19 a different compiler than on 1.18 when reconfiguring"

gcampbell-msft commented 2 months ago

Okay, to fully be able to understand and investigate your issue, could you please create a new issue with a detailed repro project, repro steps, and the output of the cmake "Log Diagnostics" output?

gcampbell-msft commented 2 months ago

@DanKing-dev I wonder if your issue is actually #4005. It's using a different generator and so it's grabbing a different compiler? Are you using kits?

Either way, follow the steps from my last comment in order to get the best help. Thanks.