{"id":19605,"date":"2018-06-27T15:00:02","date_gmt":"2018-06-27T22:00:02","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=19605"},"modified":"2019-02-18T17:47:51","modified_gmt":"2019-02-18T17:47:51","slug":"cmake-support-in-visual-studio-configuration-templates","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-support-in-visual-studio-configuration-templates\/","title":{"rendered":"CMake Support in Visual Studio \u2013 Configuration Templates"},"content":{"rendered":"<p><span><a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2017 15.8 Preview 3<\/a><\/span> is now available and it includes several improvements to the CMake tools. In addition to a few fixes we have simplified the way you can configure your CMakeSettings.json file by adding configuration templates.<\/p>\n<p><em>If you are new to CMake in Visual Studio, check out <span><a href=\"https:\/\/aka.ms\/cmake\">how to get started<\/a><\/span>.<\/em><\/p>\n<h3>Configuration Templates for CMake<\/h3>\n<p>If you have created a CMakeSettings.json file to customize your project\u2019s settings in the past you might know that that file could be a little daunting. With both the Desktop and Linux workloads installed, the default CMakeSettings.json template was over 100 lines long. We received feedback from the community that this file was difficult to unpack and understand, so we have simplified the way we populate the default CMakeSettings.json file. We have also provided a way to access and edit this configuration file directly from the configuration selector.<\/p>\n<h4>Getting Started<\/h4>\n<p>When you open a CMake folder for the first time, we now implicitly create just one debug configuration that matches the current operating system. This way, you are still able to get up and running to target the local machine without needing to create a CMakeSettings.json file at all. However, once you do want to add or customize the CMake configuration list, it is easier than ever to do so:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Create-CMakeSettings-from-Config-Dropdown.png\"><img decoding=\"async\" width=\"405\" height=\"85\" class=\"size-full wp-image-19615 aligncenter\" alt=\"Create CMakeSettings from Config Dropdown\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Create-CMakeSettings-from-Config-Dropdown.png\" \/><\/a><\/p>\n<p>Clicking \u201cManage Configurations\u2026\u201d in the configuration selection dropdown (right of the F5 button) will ask you to select a template that best fits how you want to debug your project. Visual Studio will add the selected template to a newly created CMakeSettings.json in the root CMakeLists file\u2019s folder.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Configuration-Template-Selector.png\"><img decoding=\"async\" width=\"436\" height=\"538\" class=\"size-full wp-image-19625 aligncenter\" alt=\"Configuration Template Selector\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Configuration-Template-Selector.png\" \/><\/a><\/p>\n<p>This has all the configurations we supported before plus a few new ones for targeting MinGW and ARM IoT devices. Once you select a template, it will be added to your CMakeSettings.json file. If we take \u201cx86-Debug\u201d for example, we see that it results in a very compact CMakeSettings.json:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Nice-and-Short-CMakeSettings.png\"><img decoding=\"async\" width=\"782\" height=\"349\" class=\"size-full wp-image-19635 aligncenter\" alt=\"New CMakeSettings.json Content\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Nice-and-Short-CMakeSettings.png\" \/><\/a><\/p>\n<p>At only 17 lines, this is quite a bit more manageable than this file has been in the past.<\/p>\n<h4>Adding New Configurations<\/h4>\n<p>Once you create this file, the \u201cManage Configurations\u2026\u201d button in the configuration selection dropdown will take you back to the CMakeSettings.json file. However, that doesn\u2019t mean you can\u2019t add more templates to it. To add new templates after creating the file just right click anywhere on the editor and select Add Configuration:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMakeSettings-Editor-Add-Configuration.png\"><img decoding=\"async\" width=\"453\" height=\"300\" class=\"size-full wp-image-19645 aligncenter\" alt=\"Add a Configuration from the Editor\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/CMakeSettings-Editor-Add-Configuration.png\" \/><\/a><\/p>\n<p>Alternatively, you can right click on the file itself in the Solution Explorer:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Add-Configuration-from-Solution-Explorer.png\"><img decoding=\"async\" width=\"376\" height=\"398\" class=\"size-full wp-image-19655 aligncenter\" alt=\"Add Configuration from the Solution Explorer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Add-Configuration-from-Solution-Explorer.png\" \/><\/a><\/p>\n<p>The newly selected template will be appended to the end of your configuration file.<\/p>\n<h4>Custom Configuration Templates (Experimental)<\/h4>\n<p>In addition to the built-in configuration templates, we have added an experimental way for you to create your own templates as well. Under Tools &gt; Options &gt; CMake there is now a \u201cCMakeSettings.json Template Directory\u201d entry:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Custom-Configuraiton-Templates.png\"><img decoding=\"async\" width=\"744\" height=\"484\" class=\"size-full wp-image-19665 aligncenter\" alt=\"Custom Templates in Tools &gt; Options &gt; CMake\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Custom-Configuraiton-Templates.png\" \/><\/a><\/p>\n<p>You can point this at a directory with one or more JSON files containing custom templates for CMake. These files can have any name, and essentially have the same format as a standard CMakeSettings.json file. The array of \u201cconfigurations\u201d will be treated as templates and will appear in the template selector. To set their description in the template sector just add a \u201cdescription\u201d field to the configuration\u2019s JSON.<\/p>\n<p>We would love to hear how you use this and if it works well for you. Your feedback will help us shape this feature in future versions of Visual Studio.<\/p>\n<h3>Community Reported Issues and Other Improvements<\/h3>\n<p>We have fixed quite a few customer reported issues in the latest Visual Studio Preview, including several related to our IDE integration with CTest:<\/p>\n<ul type=\"disc\">\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/243316\/cmake-configuration-fails.html\"><span>CMake configuration fails with stack trace in Output Window<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/224238\/cmake-vcpkg-problem-parameter-name-file-actual-val.html\"><span>CMake + vcpkg problem<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/240025\/vs2017-test-explorer-and-ctest-run-from-different.html\"><span>Test Explorer and CTest run from different directories<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/98182\/c-quick-actions-create-definition-for-a-member-fun-1.html\"><span>C++ Quick Actions Create Definition for a member function returns unknown error<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/210188\/cmake-tests-environment-variables-ignored.html\"><span>CMake + Tests: Environment variables ignored<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/218057\/cmake-tests-not-being-detected-in-156.html\"><span>CMake tests not being detected in 15.6<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/228522\/cmake-test-explorer-doesnt-escape-arguments-like-c.html\"><span>CMake: Test Explorer doesn&#8217;t escape arguments like CTest<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/230166\/cmake-support-does-not-work.html\"><span>CMake cache generation gets stuck with Catch2 repository<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/234282\/test-explorer-does-not-properly-interpret-ctest-te.html\"><span>Test Explorer does not properly interpret CTest tests with WILL_FAIL property set to TRUE<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/245822\/cmake-view-all-built-tests-does-not-display-all-ct.html\"><span>CMake View all built tests does not display all CTests<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/246360\/cmake-running-static-code-analysis-fails-to-detect.html\"><span>CMake: Running static code analysis fails to detect c++17<\/span><\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/246360\/cmake-running-static-code-analysis-fails-to-detect.html\"><span>Visual Studio Build Tools 2017 (15.7.1) missing Visual C++ tools for CMake<\/span><\/a><\/li>\n<\/ul>\n<p>In addition to the issues reported by the community, we have also addressed the following customer impacting issues:<\/p>\n<ul type=\"disc\">\n<li><span>Fixed long delay when closing some CMake projects<\/span><\/li>\n<li><span>Opening a new CMake project without closing a previously opened project no longer locks up the IDE<\/span><\/li>\n<li><span>CMake project code scanning no longer waits forever if filters are defined in &#8220;.vscode\\settings.json&#8221;<\/span><\/li>\n<li><span>C# CMake projects now default to the Visual Studio generator and F5 starts the managed\/mixed debugger (experimental)<\/span><\/li>\n<\/ul>\n<p>Thanks again to everyone who reported these issues!<\/p>\n<p><span>In addition to the changes to CMakeSettings and configuration, the latest version of the CMake tools also includes improved <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2018\/04\/09\/cmake-support-in-visual-studio-targets-view-single-file-compilation-and-cache-generation-settings\/\">single file compilation<\/a>. All errors and warnings now appear in the Error List instead of only the Output Window.<\/span><\/p>\n<p><span style=\"float: none;background-color: transparent;color: #333333;cursor: text;font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif;font-size: 16px;font-style: normal;font-variant: normal;font-weight: 400;letter-spacing: normal;line-height: 24px;text-align: left;text-decoration: none;text-indent: 0px\"><\/span><\/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 <span><a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2017 Preview<\/a><\/span> is working for you.\u00a0 If you have any feedback specific to CMake Tools, please reach out to <span><a href=\"mailto:cmake@microsoft.com\">cmake@microsoft.com<\/a><\/span>.\u00a0 For general issues please <span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a>.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2017 15.8 Preview 3 is now available and it includes several improvements to the CMake tools. In addition to a few fixes we have simplified the way you can configure your CMakeSettings.json file by adding configuration templates. If you are new to CMake in Visual Studio, check out how to get started. Configuration [&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-19605","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.8 Preview 3 is now available and it includes several improvements to the CMake tools. In addition to a few fixes we have simplified the way you can configure your CMakeSettings.json file by adding configuration templates. If you are new to CMake in Visual Studio, check out how to get started. Configuration [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19605","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=19605"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19605\/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=19605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=19605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=19605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}