{"id":19055,"date":"2018-04-09T14:40:35","date_gmt":"2018-04-09T21:40:35","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=19055"},"modified":"2019-02-18T17:47:58","modified_gmt":"2019-02-18T17:47:58","slug":"cmake-support-in-visual-studio-targets-view-single-file-compilation-and-cache-generation-settings","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-support-in-visual-studio-targets-view-single-file-compilation-and-cache-generation-settings\/","title":{"rendered":"CMake Support in Visual Studio \u2013 Targets View, Single File Compilation, and Cache Generation Settings"},"content":{"rendered":"<p style=\"text-align: left\"><a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2017 15.7 Preview 3<\/a> is now available, which includes several improvements to the CMake tools.\u00a0 The latest preview offers more control than ever over how to visualize, build, and manage your CMake projects.<\/p>\n<p>Please download the preview and check out the latest CMake features such as the Targets View, single file compilation, and more control over when projects are configured.\u00a0 As always, we would love to hear your feedback too.<\/p>\n<p><em>If you are new to CMake in Visual Studio, check out <\/em><a href=\"https:\/\/aka.ms\/cmake\"><em>how to get started<\/em><\/a><em>.<\/em><\/p>\n<h3>CMake Targets View<\/h3>\n<p>The latest preview of Visual Studio offers a new way to visualize your CMake projects\u2019 source and structure.\u00a0 When you open a CMake project in Visual Studio, you see the project\u2019s layout on disk in the Solution Explorer.\u00a0 Depending on the way your project is organized, this disk-based view may not be a good reflection of the actual organization of your CMake project.\u00a0 This is especially true if your project includes files outside of the folder or if it conditionally includes files depending on the active configuration.<\/p>\n<p>The newly added Targets View allows you to visualize the structure of a CMake project in the Solution Explorer.\u00a0 In this view, source code is organized under individual CMake targets and projects.\u00a0 You can build and debug individual targets by right clicking them in the Solution Explorer.\u00a0 You can also see the relationships and dependencies between targets under the References node.\u00a0 You also have more options to customize the displayed structure of your targets and source code \u2013 see <em>Organizing Targets and Source below.<\/em><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Targets-View.png\"><img decoding=\"async\" width=\"455\" height=\"633\" class=\"size-full wp-image-19065 aligncenter\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Targets-View.png\" \/><\/a><\/p>\n<p>You can show the Targets View by clicking on the view dropdown in the Solution Explorer:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMake-Targets-View-Sln-Explorer.png\"><img decoding=\"async\" width=\"611\" height=\"176\" class=\"size-full wp-image-19075 aligncenter\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMake-Targets-View-Sln-Explorer.png\" \/><\/a><\/p>\n<p>If you have worked with the projects and Solutions generated by CMake before, you should feel right at home.\u00a0 There is a top-level project node where CMake\u2019s Visual Studio generator would have created a Solution and each CMake target shows up under this project with its source code.\u00a0 The CMake generator would have created individual MSBuild projects for each of these targets.\u00a0 One thing to keep in mind, however, is that while the view is similar, no MSBuild projects or Solutions are created.\u00a0 The view is driven directly by the content of the CMake files.<\/p>\n<h4>Organizing Targets and Source<\/h4>\n<p>You can also control the organization of the targets and source code.\u00a0 Targets can be organized by enabling <a href=\"https:\/\/cmake.org\/cmake\/help\/v3.11\/prop_gbl\/USE_FOLDERS.html\">use_folders<\/a> and setting the <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/prop_tgt\/FOLDER.html\">folder<\/a> property for targets.\u00a0 Source code can be organized under a target using <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/command\/source_group.html\">source_groups<\/a>.\u00a0 These directives work with all CMake IDE generators (including the Visual Studio generator) so if you already have them set up they will also work with the Targets View.<\/p>\n<p>The Targets View shows a representation of the CMake project\u2019s structure.\u00a0 Currently, you cannot manipulate this structure from the Targets View.\u00a0 To modify the project\u2019s structure, you will need to manually modify your project\u2019s CMake list files.<\/p>\n<h3>Single File Compilation for CMake Projects<\/h3>\n<p>You can now build single files belonging to CMake projects just like you can for MSBuild projects.\u00a0 Right click on any file in the Solution Explorer and select \u201cCompile\u201d or build the file open in the editor via the main CMake menu:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMake-Menu-Compile.png\"><img decoding=\"async\" width=\"922\" height=\"437\" class=\"size-full wp-image-19085 aligncenter\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMake-Menu-Compile.png\" \/><\/a><\/p>\n<h3>CMake Cache Generation Settings<\/h3>\n<p>Visual Studio automatically configures and generates the cache for your CMake projects by default when you open them for the first time.\u00a0 This allows the IDE to provide a rich editing, build, and debugging experience, often requiring no additional configuration.\u00a0 However, we understand that this doesn\u2019t make sense for all projects, so we now offer new settings to control the generation of the CMake project cache:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cache-Gen-Settings.png\"><img decoding=\"async\" width=\"1053\" height=\"710\" class=\"size-full wp-image-19095 aligncenter\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cache-Gen-Settings.png\" \/><\/a><\/p>\n<p>We recommend sticking with the default, but if you commonly work with projects that require additional configuration or just want more control over how and when Visual Studio generates your CMake project cache, you may want to change this setting.\u00a0 If you disable automatic generation of the cache, Visual Studio will remind you to generate before editing code belonging to the CMake project:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cache-Gold-Bar.png\"><img decoding=\"async\" width=\"850\" height=\"48\" class=\"size-full wp-image-19105 aligncenter\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Cache-Gold-Bar.png\" \/><\/a><\/p>\n<h3>Send Us Feedback<\/h3>\n<p>Your feedback is a critical part of ensuring that we can deliver the best CMake experience.\u00a0 We would love to know how <a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2017 Preview<\/a> is working for you.\u00a0 If you have any feedback specific to CMake Tools, please reach out to <a href=\"mailto:cmake@microsoft.com\">cmake@microsoft.com<\/a>.\u00a0 For general issues please <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2017 15.7 Preview 3 is now available, which includes several improvements to the CMake tools.\u00a0 The latest preview offers more control than ever over how to visualize, build, and manage your CMake projects. Please download the preview and check out the latest CMake features such as the Targets View, single file compilation, and [&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":[266],"tags":[8,140,252,233,6,268],"class_list":["post-19055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cmake","tag-announcement","tag-c","tag-cmake","tag-cross-platform","tag-ide","tag-openfolder"],"acf":[],"blog_post_summary":"<p>Visual Studio 2017 15.7 Preview 3 is now available, which includes several improvements to the CMake tools.\u00a0 The latest preview offers more control than ever over how to visualize, build, and manage your CMake projects. Please download the preview and check out the latest CMake features such as the Targets View, single file compilation, and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19055","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=19055"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19055\/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=19055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=19055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=19055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}