Skip to content

Commit 3a57514

Browse files
author
Colin Robertson
authored
Merge pull request #3633 from MicrosoftDocs/main637769175693356488
Repo sync for protected CLA branch
2 parents 9200308 + b72b146 commit 3a57514

File tree

2 files changed

+717
-734
lines changed

2 files changed

+717
-734
lines changed

docs/linux/cmake-linux-configure.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Configure a Linux CMake project in Visual Studio"
33
description: "How to configure Linux CMake settings in Visual Studio"
4-
ms.date: "08/08/2020"
4+
ms.date: 01/03/2022
55
---
66
# Configure a Linux CMake project in Visual Studio
77

@@ -10,11 +10,11 @@ Linux support is available in Visual Studio 2017 and later. To see the documenta
1010
::: moniker-end
1111

1212
::: moniker range=">=msvc-150"
13-
This topic describes how to add a Linux configuration to a CMake project that targets either a remote Linux system or Windows Subsystem for Linux (WSL). It continues the series that began with [Create a Linux CMake project in Visual Studio](cmake-linux-project.md). If you are using MSBuild, instead, see [Configure a Linux MSBuild Project in Visual Studio](configure-a-linux-project.md)
13+
This topic describes how to add a Linux configuration to a CMake project that targets either a remote Linux system or Windows Subsystem for Linux (WSL). It continues the series that began with [Create a Linux CMake project in Visual Studio](cmake-linux-project.md). If you're using MSBuild, instead, see [Configure a Linux MSBuild Project in Visual Studio](configure-a-linux-project.md)
1414

1515
## Add a Linux configuration
1616

17-
A configuration can be used to target different platforms (Windows, WSL, a remote system) with the same source code. A configuration is also used to set your compilers, pass environment variables, and customize how CMake is invoked. The *CMakeSettings.json* file specifies some or all of 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.
17+
A configuration can be used to target different platforms (Windows, WSL, a remote system) with the same source code. A configuration is also used to set your compilers, pass environment variables, and customize how CMake is invoked. The *CMakeSettings.json* file specifies some or all of the properties listed in [Customize CMake settings](../build/customize-cmake-settings.md), plus other properties that control the build settings on the remote Linux machine.
1818
::: moniker-end
1919

2020
::: moniker range="msvc-150"
@@ -24,27 +24,36 @@ The default configuration for Linux-Debug in Visual Studio 2017 (and Visual Stud
2424

2525
```json
2626
{
27+
"configurations": [
28+
{
2729
"name": "Linux-Debug",
2830
"generator": "Unix Makefiles",
2931
"remoteMachineName": "${defaultRemoteMachineName}",
3032
"configurationType": "Debug",
3133
"remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}",
3234
"cmakeExecutable": "/usr/local/bin/cmake",
33-
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
34-
"installRoot": "${env.LOCALAPPDATA}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
35+
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
36+
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
3537
"remoteBuildRoot": "/var/tmp/build/${workspaceHash}/build/${name}",
3638
"remoteInstallRoot": "/var/tmp/build/${workspaceHash}/install/${name}",
3739
"remoteCopySources": true,
3840
"remoteCopySourcesOutputVerbosity": "Normal",
3941
"remoteCopySourcesConcurrentCopies": "10",
4042
"remoteCopySourcesMethod": "rsync",
41-
"remoteCopySourcesExclusionList": [".vs", ".git"],
42-
"rsyncCommandArgs" : "-t --delete --delete-excluded",
43-
"remoteCopyBuildOutput" : "false",
43+
"remoteCopySourcesExclusionList": [
44+
".vs",
45+
".git"
46+
],
47+
"rsyncCommandArgs": "-t --delete --delete-excluded",
48+
"remoteCopyBuildOutput": false,
4449
"cmakeCommandArgs": "",
4550
"buildCommandArgs": "",
4651
"ctestCommandArgs": "",
47-
"inheritEnvironments": [ "linux-x64" ]
52+
"inheritEnvironments": [
53+
"linux_x64"
54+
]
55+
}
56+
]
4857
}
4958
```
5059

@@ -55,16 +64,18 @@ To change the default CMake settings in Visual Studio 2019 or later, from the ma
5564

5665
![Screenshot showing CMake Manage Configurations highlighted in the Configuration dropdown.](../build/media/vs2019-cmake-manage-configurations.png "CMake configurations drop-down")
5766

58-
This command opens 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 with the JSON editor by clicking the **Edit JSON** button in the editor. For more information, see [Customize CMake Settings](../build/customize-cmake-settings.md).
67+
This command opens 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 with the JSON editor by clicking the **Edit JSON** button in the upper-right of the **CMake Settings** dialog. For more information, see [Customize CMake Settings](../build/customize-cmake-settings.md).
5968

6069
The default Linux-Debug configuration in Visual Studio 2019 version 16.1, and later, looks like this:
6170

6271
```json
6372
{
64-
"name": "Linux-Debug",
65-
"generator": "Unix Makefiles",
73+
"configurations": [
74+
{
75+
"name": "Linux-GCC-Debug",
76+
"generator": "Ninja",
6677
"configurationType": "Debug",
67-
"cmakeExecutable": "/usr/bin/cmake",
78+
"cmakeExecutable": "cmake",
6879
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
6980
"cmakeCommandArgs": "",
7081
"buildCommandArgs": "",
@@ -78,7 +89,6 @@ The default Linux-Debug configuration in Visual Studio 2019 version 16.1, and la
7889
"rsyncCommandArgs": "-t --delete --delete-excluded",
7990
"remoteCopyBuildOutput": false,
8091
"remoteCopySourcesMethod": "rsync",
81-
"addressSanitizerRuntimeFlags": "detect_leaks=0",
8292
"variables": []
8393
}
8494
]
@@ -98,7 +108,7 @@ When you do a build:
98108

99109
## Choose a Linux target
100110

101-
When you open a CMake project folder, Visual Studio parses the *CMakeLists.txt* file and specifies a Windows target of **x86-Debug**. To target a remote Linux system, you'll change the project settings based on your Linux compiler. For example, if you are using GCC on Linux and compiling with debug info, you'll chose: **Linux-GCC-Debug** or **Linux-GCC-Release**.
111+
When you open a CMake project folder, Visual Studio parses the *CMakeLists.txt* file and specifies a Windows target of **x86-Debug**. To target a remote Linux system, you'll change the project settings based on your Linux compiler. For example, if you're using GCC on Linux and compiling with debug info, choose: **Linux-GCC-Debug** or **Linux-GCC-Release**.
102112

103113
If you specify a remote Linux target, your source is copied to the remote system.
104114

@@ -121,7 +131,7 @@ The **CMakeSettings.json** window appears.
121131

122132
![Add configuration.](media/cmake-linux-configurations.png "Add a configuration to CMake settings")
123133

124-
Press **Add Configuration** (the green '+' button) and then choose **Linux-GCC-Debug** or **Linux-GCC-Release** if using GCC. Use the Clang variants if you are using the Clang/LLVM toolset. Press **Select** and then **Ctrl+S** to save the configuration.
134+
Press **Add Configuration** (the green '+' button) and then choose **Linux-GCC-Debug** or **Linux-GCC-Release** if using GCC. Use the Clang variants if you're using the Clang/LLVM toolset. Press **Select** and then **Ctrl+S** to save the configuration.
125135

126136
**Visual Studio 2019 version 16.1** When you target WSL, Visual Studio doesn't need to copy source files and maintain two synchronous copies of your build tree because the compiler on Linux has direct access to your source files in the mounted Windows file system.
127137
::: moniker-end
@@ -135,7 +145,7 @@ Accurate C++ IntelliSense requires access to the C++ headers referenced by your
135145

136146
Visual Studio language settings aren't propagated to Linux targets because Visual Studio doesn't manage or configure installed packages. Messages shown in the Output window, such as build errors, are shown using the language and locale of the Linux target. You'll need to configure your Linux targets for the desired locale.
137147

138-
## Additional settings
148+
## More settings
139149

140150
Use the following settings to run commands on the Linux system before and after building, and before CMake generation. The values can be any command that is valid on the remote system. The output is piped back to Visual Studio.
141151

0 commit comments

Comments
 (0)