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
When you install the Linux C++ workload, CMake support for Linux is selected by default. You can now work on your existing code base that uses CMake without having to convert it to a Visual Studio project. If your code base is cross-platform, you can target both Windows and Linux from within Visual Studio.
20
17
21
-
This topic assumes you have basic familiarity with CMake support in Visual Studio. For more information, see [CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md). For more information about CMake itself, see [Build, Test and Package Your Software With CMake](https://cmake.org/).
22
-
23
-
> [!NOTE]
24
-
> The CMake support in Visual Studio requires the server mode support that was introduced in CMake 3.8. If your package manager provides an older version of CMake, you can work around it by building CMake 3.8 from source.
18
+
**Visual Studio 2017 version 15.4 and later**
19
+
When you install the Linux C++ workload, CMake support for Linux is selected by default. You can now work on your existing code base that uses CMake without having to convert it to a Visual Studio project. If your code base is cross-platform, you can target both Windows and Linux from within Visual Studio.
25
20
21
+
This topic assumes you have basic familiarity with CMake support in Visual Studio. For more information, see [CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md). For more information about CMake itself, see [Build, Test and Package Your Software With CMake](https://cmake.org/).
26
22
23
+
> [!NOTE]
24
+
> The CMake support in Visual Studio requires the server mode support that was introduced in CMake 3.8. If your package manager provides an older version of CMake, you can work around it by [building CMake from source](#build-a-supported-cmake release-from-source) or downloading it from the official [CMake download page](https://cmake.org/download/).
27
25
28
26
## Open a folder
29
-
To get started, choose **File | Open | Folder** from the main menu or else type `devenv.exe <foldername>` on the command line. The folder you open should have a CMakeLists.txt file in it, along with your source code.
27
+
28
+
To get started, choose **File** > **Open** > **Folder** from the main menu or else type `devenv.exe <foldername>` on the command line. The folder you open should have a CMakeLists.txt file in it, along with your source code.
30
29
The following example shows a simple CMakeLists.txt file and .cpp file:
As soon as you open the folder, Visual Studio parses the CMakeLists.txt file and specifies a Windows target of x86-Debug. To target Linux, change the project settings to Linux-Debug or Linux-Release.
52
50
53
-
By default, Visual Studio chooses the first remote system in the list (under **Tools | Options | Cross Platform | Connection Manager**). If no remote connections are found, you are prompted to create one.
51
+
As soon as you open the folder, Visual Studio parses the CMakeLists.txt file and specifies a Windows target of **x86-Debug**. To target Linux, change the project settings to **Linux-Debug** or **Linux-Release**.
52
+
53
+
By default, Visual Studio chooses the first remote system in the list under **Tools** > **Options** > **Cross Platform** > **Connection Manager**. If no remote connections are found, you are prompted to create one.
54
54
55
-
After you specify a Linux target, your source is copied to your Linux machine. Then, CMake is run on the Linux machine to generate the CMake cache for your project.
55
+
After you specify a Linux target, your source is copied to your Linux machine. Then, CMake is run on the Linux machine to generate the CMake cache for your project.
56
56
57
-

57
+

58
58
59
-
**Visual Studio 2017 version 15.7 and later:**
59
+
**Visual Studio 2017 version 15.7 and later:**
60
60
To provide IntelliSense support for remote headers, Visual Studio automatically copies them to a directory on your local Windows machine. For more information, see [IntelliSense for remote headers](configure-a-linux-project.md#remote_intellisense).
61
61
62
-
## Debug the project
63
-
To debug your code on the remote system, set a breakpoint, select the CMake target as the startup item in the toolbar menu next to the project setting, and click run (or press F5).
62
+
## Debug the project
63
+
64
+
To debug your code on the remote system, set a breakpoint, select the CMake target as the startup item in the toolbar menu next to the project setting, and choose **⏵ Start** on the toolbar, or press F5.
65
+
66
+
To customize your program’s command line arguments, right-click on the executable in **Solution Explorer** and select **Debug and Launch Settings**. This opens or creates a launch.vs.json configuration file that contains information about your program. To specify additional arguments, add them in the `args` JSON array. For more information, see [Open Folder projects in Visual C++](https://docs.microsoft.com/en-us/cpp/ide/non-msbuild-projects).
67
+
68
+
## Configure CMake settings for Linux
64
69
65
-
## Configure CMake Settings for Linux
66
70
To change the default CMake settings, choose **CMake | Change CMake Settings | CMakeLists.txt** from the main menu, or right-click CMakeSettings.txt in **Solution Explorer** and choose **Change CMake Settings**. Visual Studio then creates a new file in your folder called `CMakeSettings.json` that is populated with the default configurations that are listed in the project settings menu item. The following example shows the default configuration for Linux-Debug based on the previous code example:
67
71
68
72
```json
@@ -87,7 +91,8 @@ To change the default CMake settings, choose **CMake | Change CMake Settings | C
87
91
88
92
The `name` value can be whatever you like. The `remoteMachineName` value specifies which remote system to target, in case you have more than one. IntelliSense is enabled for this field to help you select the right system. The field `remoteCMakeListsRoot` specifies where your project sources will be copied to on the remote system. The field `remoteBuildRoot` is where the build output will be generated on your remote system. That output is also copied locally to the location specified by `buildRoot`.
89
93
90
-
## Building a supported CMake release from source
94
+
## Build a supported CMake release from source
95
+
91
96
The minimum version of CMake required on your Linux machine is 3.8, and it must also support server mode. To verify this run this command:
92
97
93
98
```cmd
@@ -100,9 +105,11 @@ To verify that server mode is enabled, run:
100
105
cmake -E capabilities
101
106
```
102
107
103
-
In the output, look for “serverMode”:true. Note that even when you compile CMake from source as described below you should check the capabilities when done. Your Linux system may have limitations that prevent server mode from being enabled.
108
+
In the output, look for **"serverMode":true**. Note that even when you compile CMake from source as described below you should check the capabilities when done. Your Linux system may have limitations that prevent server mode from being enabled.
109
+
110
+
To get started building CMake from source in the shell for your Linux system, make sure your package manager is up to date, and that you have git and cmake available.
104
111
105
-
To get started building from source in the shell for your Linux system make sure your package manager is up to date, and that you have git and cmake available. First, clone the CMake sources from our repo where we use for Visual Studio's CMake support:
112
+
First, clone the CMake sources from the [Microsoft CMake repo](https://github.com/Microsoft/CMake) where we maintain a fork for Visual Studio's CMake support:
Next, to build and install the current release of CMake to /usr/local/bin, run these commands:
115
122
116
123
```cmd
117
124
mkdir out
@@ -121,13 +128,14 @@ make
121
128
sudo make install
122
129
```
123
130
124
-
The above commands build and install the current release of CMake to /usr/local/bin. Run this command to verify the version is >= 3.8 and that server mode is enabled:
131
+
Next, run this command to verify the version is >= 3.8 and that server mode is enabled:
125
132
126
133
```cmd
127
134
/usr/local/bin/cmake –version
128
135
cmake -E capabilities
129
136
```
130
137
131
-
## See Also
138
+
## See also
139
+
132
140
[Working with Project Properties](../ide/working-with-project-properties.md)
133
-
[CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md)
141
+
[CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md)
0 commit comments