{"id":25532,"date":"2020-02-07T23:07:37","date_gmt":"2020-02-07T23:07:37","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=25532"},"modified":"2020-02-07T23:08:31","modified_gmt":"2020-02-07T23:08:31","slug":"visual-studio-code-cmake-tools-extension-multi-root-workspaces-and-file-based-api","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/visual-studio-code-cmake-tools-extension-multi-root-workspaces-and-file-based-api\/","title":{"rendered":"Visual Studio Code CMake Tools Extension: Multi-root workspaces and file-based API"},"content":{"rendered":"<p>The February 2020 update of the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cmake-tools\">Visual Studio Code CMake Tools extension<\/a> is now available. This release includes two of the extension\u2019s top feature requests: <a href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/issues\/710\">file-based API support<\/a> and <a href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/issues\/271\">multi-root workspaces<\/a>. For a full list of this release\u2019s improvements check out the <a href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/releases\/tag\/1.3.0\">release notes on GitHub<\/a>.<\/p>\n<h4>Multi-root workspace support<\/h4>\n<p>The latest release of the CMake Tools extension comes with support for multi-root workspaces. This means you can have two or more folders containing a root CMakeLists.txt open side-by-side in Visual Studio Code. When a workspace contains multiple folders, the CMake Tools extension will display the <strong>active folder <\/strong>in the left-hand side of the status bar. The active folder is the folder to which all CMake-specific commands (configure, build, debug, etc.) are applied. In the following example my active folder is CMakeProject-1.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25533 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/statusBar.png\" alt=\"Status bar in Visual Studio Code shows the active folder in the left-hand corner, before the active debug target.\" width=\"767\" height=\"34\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/statusBar.png 767w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/statusBar-300x13.png 300w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/p>\n<p>By default, the active folder will change based on your file context. Viewing or editing a file in CMakeProject-1 will cause CMakeProject-1 to be the active folder, while viewing or editing a file in CMakeProject-2 will cause CMakeProject-2 to be the active folder. You can temporarily override the active folder by selecting the active folder in the status bar or running the <strong>CMake: Select Active Folder <\/strong>command.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25534 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/selectWorkspace.png\" alt=\"The CMake: Select Active Folder command prompts you to select the active CMake folder.\" width=\"632\" height=\"115\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/selectWorkspace.png 632w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/selectWorkspace-300x55.png 300w\" sizes=\"(max-width: 632px) 100vw, 632px\" \/><\/p>\n<p>You can also disable this behavior by setting the <a href=\"https:\/\/code.visualstudio.com\/docs\/getstarted\/settings\">user-level or workspace-level setting<\/a> <strong>CMake:<\/strong> <strong>Auto Select Active Folder<\/strong> to false. To open your workspace settings, use the command \u201cWorkspaces: Open Workspace Configuration File\u201d. If cmake.autoSelectActiveFolder is set to false then your active folder will only change if you manually run the <strong>CMake: Select Active Folder<\/strong> command.<\/p>\n<p>Finally, the CMake Tools extension has also added new commands like <strong>CMake: Configure All Projects <\/strong>and <strong>CMake: Build All Projects <\/strong>to apply existing CMake commands to all the folders in your workspace. These commands are only available when you have more than one folder open in your workspace.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-25535 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/allCommands.png\" alt=\"'All' CMake commands apply to all folders in the workspace, not just the active folder.\" width=\"619\" height=\"305\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/allCommands.png 619w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2020\/02\/allCommands-300x148.png 300w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/><\/p>\n<p>Commands to configure, build, clean, rebuild and reconfigure all projects are also available from the <strong>CMake: Project Outline<\/strong> view.<\/p>\n<h4>File-based API<\/h4>\n<p>Thank you to <a href=\"https:\/\/github.com\/KoeMai\">@KoeMai<\/a> for submitting this PR!<\/p>\n<p>CMake version 3.14 introduced <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/manual\/cmake-file-api.7.html\">file-based API<\/a>, which is a new way for clients (like the CMake Tools extension) to get semantic information about the underlying build system generated by CMake. It allows the client to write query files prior to build system generation. During build system generation CMake will read those query files and write object model response files for the client to read. Previously the CMake Tools extension only supported <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/manual\/cmake-server.7.html\">cmake-server<\/a> mode, which was deprecated with CMake version 3.15. File-based API provides a faster and more streamlined way for the extension to populate the editor with information specific to your project structure because it is reading response files instead of running CMake in long-running server mode.<\/p>\n<p>The latest release of the CMake Tools extension supports file-based API. The setting <strong>CMake: CMake Communication Mode <\/strong>has been added with the following possible values. The default value is <strong>automatic<\/strong>.<\/p>\n<ul>\n<li>automatic: uses file-api if CMake version is &gt;= 3.14 and falls back to cmake-server if CMake version is &lt; 3.14<\/li>\n<li>fileApi<\/li>\n<li>serverApi<\/li>\n<li>legacy: use only with old CMake versions &lt;= 3.7. Functionality will be reduced<\/li>\n<\/ul>\n<h4>Feedback is welcome<\/h4>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cmake-tools&amp;ssr=false#overview\">Download the CMake Tools extension for Visual Studio Code<\/a>\u00a0today and give it a try. If you run into issues or have suggestions for the team, please report them in the\u00a0<a href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/issues\">issues section of the extension\u2019s GitHub repository<\/a>. You can also reach the team via email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>) and Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The February 2020 update of the Visual Studio Code CMake Tools extension is now available. This release includes two of the extension\u2019s top feature requests: file-based API support and multi-root workspaces. For a full list of this release\u2019s improvements check out the release notes on GitHub. Multi-root workspace support The latest release of the CMake [&hellip;]<\/p>\n","protected":false},"author":2953,"featured_media":25535,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266,275],"tags":[],"class_list":["post-25532","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","category-visual-studio-code"],"acf":[],"blog_post_summary":"<p>The February 2020 update of the Visual Studio Code CMake Tools extension is now available. This release includes two of the extension\u2019s top feature requests: file-based API support and multi-root workspaces. For a full list of this release\u2019s improvements check out the release notes on GitHub. Multi-root workspace support The latest release of the CMake [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25532","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\/2953"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=25532"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/25535"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=25532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=25532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=25532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}