You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -51,52 +51,52 @@ Visual Studio defines a CMake project as a folder with a `CMakeLists.txt` file a
51
51
52
52
3. From the Visual Studio **Get started** screen, select **Create a new project**.
53
53
54
-

54
+

55
55
56
56
4. In the **Search for templates** textbox, type "cmake". Choose the **CMake Project** type and select **Next**. Give the project a name and location, and then select **Create**.
57
57
58
58
5. Enable Visual Studio's CMake Presets integration. Select **Tools**>**Options**>**CMake**>**General**. Select **Prefer using CMake Presets for configure, build, and test**, thenselect**OK**. Instead, you could have added a `CMakePresets.json` file to the root of the project. For more information, see [Enable CMake Presets integration](cmake-presets-vs.md#enable-cmakepresets-json-integration).
59
59
60
-

60
+

61
61
62
62
6. To activate the integration: from the main menu, select**File**>**Close Folder**. The **Get started** page appears. Under **Open recent**, selectthe folder you just closed to reopen the folder.
63
63
64
64
7. There are three dropdowns across the Visual Studio main menu bar. Use the dropdown on the left to selectyour active target system. This is the system where CMake will be invoked to configure and build the project. Visual Studio queries for WSL installations with `wsl -l -v`. In the following image, **WSL2: Ubuntu-20.04** is shown selected as the **Target System**.
65
65
66
-

66
+

67
67
68
68
> [!NOTE]
69
69
> If Visual Studio starts to configure your project automatically, read step 11 to manage CMake binary deployment, and thencontinue to the step below. To customize this behavior, see [Modify automatic configuration and cache notifications](cmake-presets-vs.md#modify-automatic-configuration-and-cache-notifications).
70
70
71
71
8. Use the dropdown in the middle to selectyour active Configure Preset. Configure Presets tell Visual Studio how to invoke CMake and generate the underlying build system. In step 7, the active Configure Preset is the **linux-default** Preset created by Visual Studio. To create a custom Configure Preset, select**Manage Configurations…** For more information about Configure Presets, see [Select a Configure Preset](cmake-presets-vs.md#select-a-configure-preset) and [Edit Presets](cmake-presets-vs.md#edit-presets).
9. Use the dropdown on the right to selectyour active Build Preset. Build Presets tell Visual Studio how to invoke build. In the illustration for step 7, the active Build Preset is the **Default** Build Preset created by Visual Studio. For more information about Build Presets, see [Select a Build Preset](cmake-presets-vs.md#select-a-build-preset).
76
76
77
77
10. Configure the project on WSL 2. If project generation doesn't start automatically, then manually invoke configure with **Project** > **Configure** *project-name*
11. If you don't have a supported version of CMake installed on your WSL 2 distro, then Visual Studio will prompt you beneath the main menu ribbon to deploy a recent version of CMake. Select **Yes** to deploy CMake binaries to your WSL 2 distro.
82
82
83
-

83
+

84
84
85
85
12. Confirm that the configure step has completed and that you can see the **CMake generation finished** message in the **Output** window under the **CMake** pane. Build files are written to a directory in the WSL 2 distro's file system.
86
86
87
-

87
+

88
88
89
89
13. Select the active debug target. The debug dropdown menu lists all the CMake targets available to the project.
90
90
91
-

91
+

92
92
93
93
14. Expand the project subfolder in the **Solution Explorer**. In the `CMakeProject.cpp` file, set a breakpoint in `main()`. You can also navigate to CMake targets view by selecting the View Picker button in the **Solution Explorer**, highlighted in following screenshot:
94
94
95
-

95
+

96
96
97
97
15. Select **Debug** > **Start**, or press **F5**. Your project will build, the executable will launch on your WSL 2 distro, and Visual Studio will stop execution at the breakpoint. You can see the output of your program (in this case, `"Hello CMake."`) in the Linux Console Window:
98
98
99
-

99
+

100
100
101
101
You've now built and debugged a C++ app with WSL 2 and Visual Studio 2022.
102
102
@@ -118,11 +118,15 @@ You can change the IntelliSense mode, or specify other IntelliSense options, in
118
118
119
119
## WSL 2 and MSBuild-based Linux projects
120
120
121
-
CMake is recommended forall C++ cross-platform development with Visual Studio because it allows you to build and debug the same project on Windows, WSL, and remote systems. If you're already using a MSBuild-based Linux project, then you can upgrade to the WSL 2 toolsetin Visual Studio via **Property pages**>**General**>**Platform Toolset**:
121
+
CMake is recommended for all C++ cross-platform development with Visual Studio because it allows you to build and debug the same project on Windows, WSL, and remote systems.
122
122
123
-

123
+
But you may have a MSBuild-based Linux project.
124
124
125
-
If you're targeting a WSL 2 distribution and you don't want to use the WSL 2 toolset, thenin**Property Pages**>**General**>**Platform Toolset**, selectthe**GCC forWindows Subsystem for Linux** or **Clang for Windows Subsystem for Linux** toolset. If either of these toolsets are selected, Visual Studio won't maintain a copy of your source filesin the WSL file system and will instead access source files over the mounted Windows drive (`/mnt/`…). System headers are still automatically copied to the Windows file system to provide a native IntelliSense experience. Customize the headers that are included or excluded from this copy in**Property Pages**>**General**.
125
+
If you have a MSBuild-based Linux project, then you can upgrade to the WSL 2 toolset in Visual Studio. Right-click the project in the solution explorer, then choose **Properties**>**General**>**Platform Toolset**:
126
+
127
+

128
+
129
+
If you're targeting a WSL 2 distribution and you don't want to use the WSL 2 toolset, thenin the **Platform Toolset** dropdown, selectthe**GCC forWindows Subsystem for Linux** or **Clang for Windows Subsystem for Linux** toolset. If either of these toolsets are selected, Visual Studio won't maintain a copy of your source filesin the WSL file system and will instead access source files over the mounted Windows drive (`/mnt/`…). System headers are still automatically copied to the Windows file system to provide a native IntelliSense experience. Customize the headers that are included or excluded from this copy in**Property Pages**>**General**.
126
130
127
131
In most cases, it's best to use the WSL 2 toolset with WSL 2 distributions because WSL 2 is slower when project files are stored in the Windows file system. To to learn more, see [Comparing WSL 1 and WSL 2](/windows/wsl/compare-versions).
0 commit comments