Latest Updates for CMake Development in Visual Studio

Sinem Akinci

Visual Studio has native CMake integration that allows C++ users to build and develop using CMake and supports their unique needs. CMake is a cross-platform build tool for C++ and with Visual Studio’s latest tools, users can be more productive when it comes to configuring with CMake. To learn more about Visual Studio’s CMake integration, please see our documentation: CMake projects in Visual Studio | Microsoft Learn. 

To add to the available tools for your CMake workflows, in the last year, we have delivered a new CMake debugger that allows users to debug their CMakeLists.txt files just like you would any other C++ file. Additionally, Visual Studio’s CMake integration includes the CMake Targets View, which allows users to visualize your CMake project structure by the CMake targets and build specified target libraries rather than the traditional folder structure available through the Folder View in the Solution Explorer. To make this view easier to navigate, we have implemented a few new improvements such as simplified source navigation and allowing for customized targets to exclude from the view 

Debug your CMake scripts with the new CMake Debugger

The VS CMake team has worked closely with Kitware on developing a debugger for CMake scripts in the Visual Studio IDE, with the upstreamed work available in the 3.27 release of CMake. This way, you can dive right into debugging your CMakeLists.txt files behind your CMake builds and understand the state of various variables during your configure. 

To initiate a CMake debugging session, you can select Configure [Project Name] with CMake Debugger from the Project dropdown menu, or when right-clicking on your CMakeLists.txt file in the Solution Explorer. 

Project dropdown to configure with CMake debugger

When CMake cache generation on your project fails, a “Debug” link will also be available in the Solution Explorer to start a CMake debugging session. 

Image showing CMake generation failed and a way to debug.

From here, you can do any actions you can do in your other Visual Studio debugging sessions, such as view call stacks, view CMake cache variables and targets, set breakpoints on CMake exceptions, and set watches on variables. A screenshot of the CMake debugger in action

CMake Targets View Improvements

The CMake Targets View in Visual Studio can be helpful to CMake users to have a different way to visualize their project by the buildable targets rather than a traditional folder structure. Users can switch to the CMake Targets View easier than ever when right-clicking in your Solution Explorer in a CMake project. 

Option to switch to CMake Targets View

Additionally, it can be found at View > CMake Targets at any point in a CMake project. 

Option to select CMake Targets from dropdown

From the Targets View, you’ll be able to see the list of all your buildable targets, with options to build or debug from here. You will only see the folders with buildable executables, making it easier than ever to navigate to your desired targets. 

CMake Targets View

You can define items to hide from this view that are not active targets you are working with through your VSWorkspaceSettings.json in the CMakeTargetsViewExcludedItems field. This field supports the following syntax and identifiers: 

“identifiers”:CMakeProject, CMakeTarget, CMakeReference, CMakeFolder, CMakeFile. 

Syntax for theCMakeTargetsViewExcludedItems is the following: <identifier>:<name> 

This will specify any identifier with the specified name. 

  • For example, CMakeTarget:app. Any CMake targets with the name “app” anywhere in the CMake Targets View will be excluded. 

Additionally, if you want to specify specific items to be excluded, you can use a|to chain declarations together:<identifier>:<name>|<identifier>:<name>... 

  • For example, CMakeProject:thirdPartyDependency|CMakeTarget:irrelevantThirdParty. 

Example usage in a VSWorkspaceSettings.json:

{  "CMakeTargetsViewExcludedItems": [     "CMakeTarget:<name>|CMakeFile:*", "CMakeTarget<name>|*|CMakeFile:*", "CMakeTarget:<name>|*|*|CMakeFile:*" } 

Wrap Up

We appreciate the time you’ve spent reporting issues/suggestions and hope you continue to give us feedback when using Visual Studio on what you like and what we can improve. Your feedback is critical to help us make Visual Studio the best tool it can be! You can share feedback with us viaDeveloper Community: report any bugs or issues viareport a problemandshare your suggestionsfor new features or improvements to existing ones.     

Stay connected with the Visual Studio team by following us on YouTube, Twitter, LinkedIn, Twitch and on Microsoft Learn. 

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • Cengiz Anil 0

    Congratulations Sinem, we look forward to the next announcement
    Best regards

  • 杰然 许 0

    How to set up vs2022 Git repository TAB custom layout?

  • Jon Forhan 0

    CMake is a must have for me and I’m so happy the VS team supports it!!

Feedback usabilla icon