{"id":25511,"date":"2020-02-06T21:18:46","date_gmt":"2020-02-06T21:18:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=25511"},"modified":"2020-02-06T21:21:59","modified_gmt":"2020-02-06T21:21:59","slug":"easily-add-remove-and-rename-files-and-targets-in-cmake-projects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/easily-add-remove-and-rename-files-and-targets-in-cmake-projects\/","title":{"rendered":"Easily Add, Remove, and Rename Files and Targets in CMake Projects"},"content":{"rendered":"<p>It\u2019s easier than ever to work with CMake projects in <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 16.5 Preview 2<\/a>. Now you can add, remove, and rename source files and targets in your CMake projects from the IDE without manually editing your CMake scripts. When you add or remove files with the Solution Explorer, Visual Studio will automatically edit your CMake project. You can also add, remove, and rename the project\u2019s targets from the Solution Explorer\u2019s targets view.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25512 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu.png\" alt=\"\u201cAdd &gt; New Item\u201d in Solution Explorer\u2019s targets view.\" width=\"820\" height=\"637\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu.png 820w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu-300x233.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu-768x597.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/p>\n<h3>C and C++ Source Files<\/h3>\n<p>Visual Studio now tracks C and C++ source files as they are added, renamed, or removed from the Solution Explorer, automatically modifying the underlying CMake project. This feature is enabled by default as of Visual Studio 2019 16.5 Preview 2, but if you would prefer to Visual Studio to not automatically modify your project it can be turned off in Tools &gt; Options &gt; CMake, \u201cEnable automatic CMake script modification\u2026\u201d:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25513 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Modification-Options.png\" alt=\"Tools &gt; Options &gt; CMake, \u201cEnable automatic CMake script modification.\u201d\" width=\"1132\" height=\"710\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Modification-Options.png 1132w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Modification-Options-300x188.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Modification-Options-1024x642.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Modification-Options-768x482.png 768w\" sizes=\"(max-width: 1132px) 100vw, 1132px\" \/><\/p>\n<h3>Targets and References<\/h3>\n<p>The <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-support-in-visual-studio-targets-view-single-file-compilation-and-cache-generation-settings\/\">CMake targets view<\/a> offers even more functionality. From here, in addition to adding and removing files, you can add, rename, and remove targets. You can access the CMake targets view by clicking on the Solution Explorer\u2019s drop-down menu to the right of the home button:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25514 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Targets-View.png\" alt=\"Access the CMake targets view from the Solution Explorer\u2019s drop-down to the right of the home button.\" width=\"625\" height=\"275\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Targets-View.png 625w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Targets-View-300x132.png 300w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>If you have worked with solutions generated by CMake, this view will look familiar \u2013 but unlike a generated solution you will be able to change the underlying CMake project directly in the IDE. Visual Studio currently supports modifying the following:<\/p>\n<p><strong>1. Adding, removing, renaming source files in a target:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-25515\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu-Small.png\" alt=\"CMake Targets View Add Item Menu.\" width=\"758\" height=\"210\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu-Small.png 758w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Targets-View-Add-Menu-Small-300x83.png 300w\" sizes=\"(max-width: 758px) 100vw, 758px\" \/><\/p>\n<p><strong>2. Adding, removing, renaming targets in a CMake project:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-25519\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Menu.png\" alt=\"Add Target Menu.\" width=\"716\" height=\"218\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Menu.png 716w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Menu-300x91.png 300w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-25520\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Dialog.png\" alt=\"Add Target Dialog.\" width=\"618\" height=\"338\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Dialog.png 618w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/Add-Target-Dialog-300x164.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/p>\n<p><strong>3. Viewing and creating references between targets in the project:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-25521\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Ref-Manager.png\" alt=\"Add reference dialog.\" width=\"1180\" height=\"815\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Ref-Manager.png 1180w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Ref-Manager-300x207.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Ref-Manager-1024x707.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Ref-Manager-768x530.png 768w\" sizes=\"(max-width: 1180px) 100vw, 1180px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-25522\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Refereneces-List.png\" alt=\"CMake references list.\" width=\"408\" height=\"274\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Refereneces-List.png 408w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Refereneces-List-300x201.png 300w\" sizes=\"(max-width: 408px) 100vw, 408px\" \/><\/p>\n<h3>Resolving Ambiguity<\/h3>\n<p>In some cases, there may be more than one place where it makes sense to add a source file to a CMake script. When this happens, Visual Studio will ask you where you want to make the change and display a preview of the proposed modifications:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25523 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Project-Editor-Reslove-Ambiguity.png\" alt=\"Resolve ambiguity with the preview changes dialog..\" width=\"982\" height=\"519\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Project-Editor-Reslove-Ambiguity.png 982w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Project-Editor-Reslove-Ambiguity-300x159.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/CMake-Project-Editor-Reslove-Ambiguity-768x406.png 768w\" sizes=\"(max-width: 982px) 100vw, 982px\" \/><\/p>\n<h3>Send Us Feedback<\/h3>\n<p>Please try out the\u00a0<a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">latest preview<\/a>\u00a0and let us know if you have any feedback. It is always appreciated! The best way to get in touch with us about an issue or suggestion is though Developer Community with the \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio\">Report a Problem<\/a>\u201d or \u201cSuggest a Feature\u201d tools. This makes it easy for us to follow up and for you to get the latest updates about our progress. Feel free to comment here or send an email to\u00a0<a href=\"mailto:cmake@microsoft.com\">cmake@microsoft.com<\/a>\u00a0with questions as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s easier than ever to work with CMake projects in Visual Studio 2019 16.5 Preview 2. Now you can add, remove, and rename source files and targets in your CMake projects from the IDE without manually editing your CMake scripts. When you add or remove files with the Solution Explorer, Visual Studio will automatically edit [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266],"tags":[8,252],"class_list":["post-25511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","tag-announcement","tag-cmake"],"acf":[],"blog_post_summary":"<p>It\u2019s easier than ever to work with CMake projects in Visual Studio 2019 16.5 Preview 2. Now you can add, remove, and rename source files and targets in your CMake projects from the IDE without manually editing your CMake scripts. When you add or remove files with the Solution Explorer, Visual Studio will automatically edit [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=25511"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25511\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=25511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=25511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=25511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}