The CMake Targets View in Visual Studio is a view that allows you to visualize your CMake project structure by the CMake targets and build specified target libraries and executables. To make this view more usable, we have implemented a few new improvements to make it easier than ever to navigate your CMake targets. This includes improved navigation to the CMake Targets View, a new, more simplified CMake Targets View, and the ability to exclude specified CMake items from the Targets View. Additionally, we have future planned work in the near-term to allow users to customize this view to their desired configuration. Download the latest preview version of Visual Studio to try out the new updates for the CMake Targets View.
Get to your CMake Targets View Quicker Than Ever
Customers have reported that it can be cumbersome to switch between CMake Targets View and the Solution Explorer. To address this, we have implemented new entry points to open the CMake Targets View much more quickly.
Switch to your CMake Targets View from Solution Explorer
Now, you can right-click anywhere in your Solution Explorer and simply navigate to the CMake Targets View from the context menu.
Open the CMake Targets View from the ‘View’ Dropdown Menu
You can also access the CMake Targets View globally at any point in your CMake projects by selecting from the View dropdown.
Simplify your Source Navigation
The CMake Targets View has been further simplified so that users don’t have to click through folders without buildable executables to get to their desired target.
Define Items to Exclude from View
You can now define in your VSWorkspaceSettings.json items to exclude from the CMake Targets View using the new CMakeTargetsViewExcludedItems
field. The CMakeTargetsViewExcludedItems
field is an array of strings. The field supports the following syntax and identifiers:
Supported “identifiers”: CMakeProject
, CMakeTarget
, CMakeReference
, CMakeFolder
, CMakeFile
.
Syntax for the CMakeTargetsViewExcludedItems
 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:*" }
What’s Coming Next?
We are continuing to develop the CMake Targets View to allow for further customization of this view based on customer feedback. Stay tuned for the latest updates as these ship in the future!
- We are planning to give users the ability to filter their CMake Targets view by type of target, project, etc.
- Users will be able to dynamically pin and unpin their most used targets to the top of the CMake Targets View.
We are using this suggestion ticket to track any other requests you may have for improvements to the CMake Targets View to meet your CMake needs: CMake Targets View Suggestions – Developer Community (visualstudio.com)
Anything else?
You can also find us on Twitter (@VisualC) or via email at visualcpp@microsoft.com. To open a bug, please see Visual Studio Feedback.
i am not usually updated on vs2022, but seeing this is so great!! i just opened llama.cpp github repo as a folder (not sln), and then switched to cmake targets view, and it becomes really easy to see what is building what. Although llama.cpp actually generates all *.sln files, but just thinking if it didnt this feature would have helped a lot of people.
But what about the simple old make? is it already supported...
Hi Sinem,
Is there way to see shared files and the folders they reside in under the respective CMake Targets view entry?
Suppose I have an executable MyApp with its CMakeList.txt.
The related view displays nicely all references and precompiled header related stuff.
I really like to be able to navigate to shared source files included in MyApp which does not have their own CMake target.
In the CMakeList.txt, for shared files I do it like...
Hi Muharrem,
As it stands right now, if files are in multiple CMake targets, it should do this by default. However, it requires that you include these files in the target. If these files aren't included in the target, it won't show up in the CMake Targets View as it stands, because this view is scoped to CMake targets. You could see the status of these variables if you are interested with the CMake debugger, but...
This is good but can you speed up the development of the Visual Studio Code CMake extension. It appears stalled. There a few feature requests that should be added.
Hi Hristo,
Please let us know what you would like to specifically see added to the CMake Tools extension by filing an issue in our GitHub: https://github.com/microsoft/vscode-cmake-tools/issues
Thanks,
Sinem