If you are working on a CMake project that targets Linux, you may have encountered some challenges when trying to debug your CMake scripts and CMakeLists.txt files. You may have wondered why your variables are not set correctly, or why your custom commands are not executed as expected. Or you may have simply wanted to step through your CMake scripts and see what is happening behind the scenes of the configure step.
We are excited to announce that the CMake debugger in Visual Studio now has support for CMake projects targeting Linux via WSL or SSH. The CMake debugger allows you to debug your CMake scripts and CMakeLists.txt files using the familiar Visual Studio debugger experience.
You will need CMake version 3.27 or greater installed on your remote Linux machine to have access to the CMake debugging feature.
How to use the CMake debugger
Using the CMake debugger is straightforward in Visual Studio. All you need to do is set a breakpoint in your CMakeLists.txt file or any .cmake script file and then navigate to Project > Configure Cache with CMake Debugging.
This will launch the CMake debugger and stop at your breakpoint. You can then inspect the values of your CMake variables, evaluate expressions, watch the output of your custom commands, and step through your CMake code using the familiar Visual Studio debugger.
Linux Machine Compatibility
The CMake debugger works for both WSL and SSH connections. WSL connections are automatically detected in Visual Studio and you can add SSH connections via the Connection Manager under Tools > Options and then Cross Platform > Connection Manager.
You can always toggle the target machine in your CMake projects by using the Target System dropdown in the top of Visual Studio.
What’s next?
We hope you enjoy using the CMake debugger and find it useful for your CMake projects. We would love to hear your feedback and suggestions on how to improve it further. Please let us know what you think by using the Send Feedback button in Visual Studio.
Thank you for your continuous feedback and support that make Visual Studio better every day.