I’m using Visual Studio to connect to a docker container via SSH for remote development using CMake as the build system.
When Visual Studio launches the project for the first time or a CMakeLists.txt file has been altered, Visual Studio does some configuration, allowing me to view, compile and run the CMake targets, and other CMake settings also become available in the UI, however, when reopening the project, Visual Studio does not seem to detect the CMake Project or reconfigure automatically, meaning no targets are shown hence not possible to compile, or if shown don’t work, and no settings for CMake are shown in the UI; I could theoretically update a CMakeLists.txt file which after relaunching again could cause a regenerate, causing Visual Studio to detect the project, show the targets and general settings relating to CMake in the UI, but this is not ideal and could cause the entire project to require recompiling.
Steps to reproduce:
- Create C++ CMake Project in Visual Studio 2022
- Run Docker container and add SSH connection info in Visual Studio options
- Replace the default ‘x64-Debug’ in CMakeSettings.json with ‘Linux-GCC-Debug’
- Wait for automatic CMake generation or press Generate on the popup “C++ IntelliSense information may be out of date, generate the CMake cache to refresh…”
- Everything works perfectly now; the “Select Startup Item” menu button should be available to select, compile and execute the target/s specified from the CMakeLists.txt files. Other CMake buttons should now be available in the UI, (e.g. Project → Configure Cache)
- Quit Visual Studio
- Open the project again in Visual Studio
- There does not appear to be a way to restore the working state, Visual Studio does not know the CMake targets anymore, we can no longer compile the project, nor run it. There appears no way to cause Visual Studio to reconfigure within the UI. The existing targets may appear, but no longer work.
I have then followed the tutorial for remote cache: Open Existing CMake Caches in Visual Studio - C++ Team Blog
Doing the steps:
- Replace configuration ‘Linux-GCC-Debug’ with ‘Existing Cache (Remote)’
- Update cacheRoot to the path that contains CMakeList.txt on the remote system
The regenerate popup shows ( “C++ IntelliSense information may be out of date, generate the CMake cache to refresh…” ), pressing regenerate works the first time, but then subsequent re openings of the project result in nothing happening again. No targets / executables to choose.
This issue does not occur for local MSVC CMake projects, the available targets are always shown immediately upon relaunch, along with all other Project settings being available in the UI.
Could this be a bug in Visual Studio, or, is there something I’m missing so that Visual Studio always uses the existing cache to configure itself to make the targets available for compiling and executing, whenever I launch the existing project?
How do IDE’s discover the CMake targets?