Skip to content

Commit a67da15

Browse files
author
Colin Robertson
committed
Address other issues, Acrolinx
1 parent e50c0bc commit a67da15

File tree

2 files changed

+88
-80
lines changed

2 files changed

+88
-80
lines changed

docs/linux/cmake-linux-project.md

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,11 @@ ms.assetid: f8707b32-f90d-494d-ae0b-1d44425fdc25
88

99
::: moniker range="vs-2015"
1010

11-
Linux support is available in Visual Studio 2017 and later.
11+
Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the Visual Studio **Version** selector control for this article to Visual Studio 2017 or Visual Studio 2019. It's found at the top of the table of contents on this page.
1212

1313
::: moniker-end
1414

15-
::: moniker range="vs-2019"
16-
17-
To create a new Linux CMake project in Visual Studio 2019:
18-
19-
1. Select **File > New Project** in Visual Studio, or press **Ctrl + Shift + N**.
20-
1. Set the **Language** to **C++** and search for "CMake". Then choose **Next**. Enter a **Name** and **Location**, and choose **Create**.
21-
22-
Visual Studio creates a minimal *CMakeLists.txt* file with only the name of the executable and the minimum CMake version required. You can manually edit this file however you like; Visual Studio will never overwrite your changes. You can specify CMake command-line arguments and environment variables in this file. Right-click on the root *CMakeLists.txt* file in **Solution Explorer** and choose **CMake settings for project**. To specify options for debugging, right-click on the project node and choose **Debug and launch settings**.
23-
24-
::: moniker-end
25-
26-
When you open a folder that contains an existing CMake project, Visual Studio uses variables in the CMake cache to automatically configure IntelliSense and builds. Local configuration and debugging settings get stored in JSON files. You can optionally share these files with others who are using Visual Studio.
27-
28-
Visual Studio doesn't modify the *CMakeLists.txt* files. It's left alone so that others working on the same project can continue to use their existing tools. Visual Studio does regenerate the cache when you save edits to *CMakeLists.txt* or in some cases to *CMakeSettings.json*. But if you're using an **Existing Cache** configuration, then Visual Studio doesn't modify the cache.
29-
30-
For general information about CMake support in Visual Studio, see [CMake projects in Visual Studio](../build/cmake-projects-in-visual-studio.md). Read that first before continuing here.
15+
::: moniker range=">=vs-2017"
3116

3217
## Before you begin
3318

@@ -41,6 +26,8 @@ On the Linux system, make sure that the following are installed:
4126
- zip
4227
- ninja-build
4328

29+
::: moniker-end
30+
4431
::: moniker range="vs-2019"
4532

4633
Linux support for CMake projects requires the target machine to have a recent version of CMake. Often, the version offered by a distribution’s default package manager isn't recent enough to support all the features required by Visual Studio. Visual Studio 2019 detects whether a recent version of CMake is installed on the Linux system. If none is found, Visual Studio shows an info-bar at the top of the editor pane. It offers to install CMake for you from [https://github.com/Microsoft/CMake/releases](https://github.com/Microsoft/CMake/releases).
@@ -57,7 +44,28 @@ The binaries are installed in `~/.vs/cmake`. After deploying the binaries, your
5744

5845
:::moniker-end
5946

60-
## Open a folder
47+
::: moniker range="vs-2019"
48+
49+
## Create a new Linux CMake project
50+
51+
To create a new Linux CMake project in Visual Studio 2019:
52+
53+
1. Select **File > New Project** in Visual Studio, or press **Ctrl + Shift + N**.
54+
1. Set the **Language** to **C++** and search for "CMake". Then choose **Next**. Enter a **Name** and **Location**, and choose **Create**.
55+
56+
Visual Studio creates a minimal *CMakeLists.txt* file with only the name of the executable and the minimum CMake version required. You can manually edit this file however you like; Visual Studio will never overwrite your changes. You can specify CMake command-line arguments and environment variables in this file. Right-click on the root *CMakeLists.txt* file in **Solution Explorer** and choose **CMake settings for project**. To specify options for debugging, right-click on the project node and choose **Debug and launch settings**.
57+
58+
::: moniker-end
59+
60+
::: moniker range=">=vs-2017"
61+
62+
## Open a CMake project folder
63+
64+
When you open a folder that contains an existing CMake project, Visual Studio uses variables in the CMake cache to automatically configure IntelliSense and builds. Local configuration and debugging settings get stored in JSON files. You can optionally share these files with others who are using Visual Studio.
65+
66+
Visual Studio doesn't modify the *CMakeLists.txt* files. It's left alone so that others working on the same project can continue to use their existing tools. Visual Studio does regenerate the cache when you save edits to *CMakeLists.txt* or in some cases to *CMakeSettings.json*. But if you're using an **Existing Cache** configuration, then Visual Studio doesn't modify the cache.
67+
68+
For general information about CMake support in Visual Studio, see [CMake projects in Visual Studio](../build/cmake-projects-in-visual-studio.md). Read that first before continuing here.
6169

6270
To get started, choose **File** > **Open** > **Folder** from the main menu or else type `devenv.exe <foldername>` in a [developer command prompt](../build/building-on-the-command-line.md) window. The folder you open should have a *CMakeLists.txt* file in it, along with your source code.
6371

@@ -76,7 +84,7 @@ int main(int argc, char* argv[])
7684
7785
*CMakeLists.txt*:
7886
79-
```cmd
87+
```txt
8088
cmake_minimum_required(VERSION 3.8)
8189
project (hello-cmake)
8290
add_executable(hello-cmake hello.cpp)
@@ -86,6 +94,8 @@ add_executable(hello-cmake hello.cpp)
8694

8795
As soon as you open the folder, Visual Studio parses the *CMakeLists.txt* file and specifies a Windows target of **x86-Debug**. To target a remote Linux system, change the project settings to **Linux-Debug** or **Linux-Release**. (See [Configure CMake settings for Linux](#configure_cmake_linux) below.)
8896

97+
::: moniker-end
98+
8999
::: moniker range="vs-2019"
90100

91101
To target Windows Subsystem for Linux, click on **Manage Configurations** in the configuration dropdown in the main toolbar. Then press the **Add Configuration** button and choose **WSL-Debug** or **WSL-Release** if using GCC. Use the Clang variants if using the Clang/LLVM toolset.
@@ -94,6 +104,8 @@ To target Windows Subsystem for Linux, click on **Manage Configurations** in the
94104

95105
::: moniker-end
96106

107+
::: moniker range=">=vs-2017"
108+
97109
Visual Studio chooses the first remote system in the list under **Tools** > **Options** > **Cross Platform** > **Connection Manager** by default for remote targets. If no remote connections are found, you're prompted to create one. For more information, see [Connect to your remote Linux computer](connect-to-your-remote-linux-computer.md).
98110

99111
If you specify a remote Linux target, your source is copied to the remote system.
@@ -125,6 +137,8 @@ To specify additional arguments, add them in the `args` JSON array. For more inf
125137

126138
A *CMakeSettings.json* file in a CMake Linux project can specify all the properties listed in [Customize CMake settings](../build/customize-cmake-settings.md), plus additional properties that control the build settings on the remote Linux machine.
127139

140+
::: moniker-end
141+
128142
::: moniker range="vs-2019"
129143

130144
To change the default CMake settings in Visual Studio 2019, from the main toolbar, open the **Configuration** dropdown and choose **Manage Configurations**.
@@ -133,11 +147,39 @@ To change the default CMake settings in Visual Studio 2019, from the main toolba
133147

134148
This command brings up the **CMake Settings Editor**, which you can use to edit the *CMakeSettings.json* file in your root project folder. You can also open the file directly by clicking the **Edit JSON** button in the editor. For more information, see [Customize CMake Settings](../build/customize-cmake-settings.md).
135149

150+
The default Linux-Debug configuration in Visual Studio 2019 version 16.1 and later is as shown here:
151+
152+
```json
153+
{
154+
"name": "Linux-Debug",
155+
"generator": "Unix Makefiles",
156+
"configurationType": "Debug",
157+
"cmakeExecutable": "/usr/bin/cmake",
158+
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
159+
"cmakeCommandArgs": "",
160+
"buildCommandArgs": "",
161+
"ctestCommandArgs": "",
162+
"inheritEnvironments": [ "linux_x64" ],
163+
"remoteMachineName": "${defaultRemoteMachineName}",
164+
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
165+
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
166+
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
167+
"remoteCopySources": true,
168+
"rsyncCommandArgs": "-t --delete --delete-excluded",
169+
"remoteCopyBuildOutput": false,
170+
"remoteCopySourcesMethod": "rsync",
171+
"addressSanitizerRuntimeFlags": "detect_leaks=0",
172+
"variables": []
173+
}
174+
]
175+
}
176+
```
177+
136178
::: moniker-end
137179

138180
::: moniker range="vs-2017"
139181

140-
To change the default CMake settings in Visual Studio 2017, 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 *CMakeSettings.json* file in your root project folder. You can open the file using the **CMake Settings** editor or modify the file directly. For more information, see [Customize CMake settings](../build/customize-cmake-settings.md).
182+
To change the default CMake settings in Visual Studio 2017, 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 *CMakeSettings.json* file in your root project folder. You can open the file using the **CMake Settings** editor or modify the file directly. For more information, see [Customize CMake settings](../build/customize-cmake-settings.md).
141183

142184
The following example shows the default configuration for Linux-Debug in Visual Studio 2017 (and Visual Studio 2019 version 16.0) based on the previous code example:
143185

@@ -169,37 +211,7 @@ The following example shows the default configuration for Linux-Debug in Visual
169211

170212
::: moniker-end
171213

172-
::: moniker range="vs-2019"
173-
174-
The default Linux-Debug configuration in Visual Studio 2019 version 16.1 and later is as shown here:
175-
176-
```json
177-
{
178-
"name": "Linux-Debug",
179-
"generator": "Unix Makefiles",
180-
"configurationType": "Debug",
181-
"cmakeExecutable": "/usr/bin/cmake",
182-
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
183-
"cmakeCommandArgs": "",
184-
"buildCommandArgs": "",
185-
"ctestCommandArgs": "",
186-
"inheritEnvironments": [ "linux_x64" ],
187-
"remoteMachineName": "${defaultRemoteMachineName}",
188-
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
189-
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
190-
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
191-
"remoteCopySources": true,
192-
"rsyncCommandArgs": "-t --delete --delete-excluded",
193-
"remoteCopyBuildOutput": false,
194-
"remoteCopySourcesMethod": "rsync",
195-
"addressSanitizerRuntimeFlags": "detect_leaks=0",
196-
"variables": []
197-
}
198-
]
199-
}
200-
```
201-
202-
::: moniker-end
214+
::: moniker range=">=vs-2017"
203215

204216
For more information about these settings, see [CMakeSettings.json reference](../build/cmakesettings-reference.md).
205217

@@ -225,4 +237,6 @@ These options allow you to run commands on the Linux system before and after bui
225237
[Customize CMake settings](../build/customize-cmake-settings.md)<br/>
226238
[Configure CMake debugging sessions](../build/configure-cmake-debugging-sessions.md)<br/>
227239
[Deploy, run, and debug your Linux project](deploy-run-and-debug-your-linux-project.md)<br/>
228-
[CMake predefined configuration reference](../build/cmake-predefined-configuration-reference.md)<br/>
240+
[CMake predefined configuration reference](../build/cmake-predefined-configuration-reference.md)
241+
242+
::: moniker-end

0 commit comments

Comments
 (0)