{"id":251054,"date":"2024-10-22T05:00:20","date_gmt":"2024-10-22T12:00:20","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=251054"},"modified":"2024-10-22T08:56:57","modified_gmt":"2024-10-22T15:56:57","slug":"debug-cmake-scripts-on-linux-with-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/debug-cmake-scripts-on-linux-with-visual-studio\/","title":{"rendered":"Debug CMake Scripts on Linux with Visual Studio"},"content":{"rendered":"<p>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 <em>CMakeLists.txt<\/em> 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.<\/p>\n<p>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 <em>CMakeLists.txt<\/em> files using the familiar Visual Studio debugger experience.<\/p>\n<p>You will need CMake version 3.27 or greater installed on your remote Linux machine to have access to the CMake debugging feature.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-251055\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1.png\" alt=\"CMake Script highlighted in parallel stack window\" width=\"1909\" height=\"1030\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1.png 1909w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1-300x162.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1-1024x552.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1-768x414.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-1-1536x829.png 1536w\" sizes=\"(max-width: 1909px) 100vw, 1909px\" \/><\/p>\n<h1>How to use the CMake debugger<\/h1>\n<p>Using the CMake debugger is straightforward in Visual Studio. All you need to do is set a breakpoint in your <em>CMakeLists.txt<\/em> file or any .cmake script file and then navigate to <strong>Project &gt; Configure Cache with CMake Debugging<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-251056\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-2.png\" alt=\"Image showing Configure Cache with CMake debugging highlighted in the Project dropdown\" width=\"610\" height=\"343\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-2.png 610w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-2-300x169.png 300w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>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.<\/p>\n<h3>Linux Machine Compatibility<\/h3>\n<p>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 <strong>Tools <\/strong>&gt; <strong>Options <\/strong>and then <strong>Cross Platform<\/strong> &gt; <strong>Connection Manager.<\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3.png\"><img decoding=\"async\" class=\"alignnone wp-image-251057 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3.png\" alt=\"Image showing the Tools, Options menu Connection Manager\" width=\"1239\" height=\"718\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3.png 1239w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3-300x174.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3-1024x593.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/word-image-251054-3-768x445.png 768w\" sizes=\"(max-width: 1239px) 100vw, 1239px\" \/><\/a><\/p>\n<p>You can always toggle the target machine in your CMake projects by using the Target System dropdown in the top of Visual Studio.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/debug-cmake-projects.png\"><img decoding=\"async\" class=\"alignnone wp-image-251061\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/debug-cmake-projects.png\" alt=\"WSL: Ubuntu highlighted \" width=\"560\" height=\"101\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/debug-cmake-projects.png 998w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/debug-cmake-projects-300x54.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/10\/debug-cmake-projects-768x139.png 768w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/a><\/p>\n<h1>What&#8217;s next?<\/h1>\n<p>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 <a href=\"https:\/\/learn.microsoft.com\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2022\">Send Feedback<\/a> button in Visual Studio.<\/p>\n<p>Thank you for your continuous feedback and support that make Visual Studio better every day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":85413,"featured_media":251056,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1195,6962,155],"tags":[5514,6793,6886],"class_list":["post-251054","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cross-platform","category-debug","category-visual-studio","tag-cmake","tag-debugger","tag-linux"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/251054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/85413"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=251054"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/251054\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/251056"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=251054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=251054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=251054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}