Skip to content

Commit 1073e2f

Browse files
mikeblomeColin Robertson
authored andcommitted
Updates to Linux - CMake content (#1556)
* updates for linux project config * more edits * initial reorg of topic content * moved debug and config sections to new topics per PM * more edits * renamed file and adjusted toc * fixed link
1 parent a66d309 commit 1073e2f

8 files changed

+325
-289
lines changed

docs/ide/TOC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# [Visual C++ Tools and Features in Visual Studio Editions](visual-cpp-tools-and-features-in-visual-studio-editions.md)
1111
# [Open Folder projects](non-msbuild-projects.md)
1212
# [CMake projects](cmake-tools-for-visual-cpp.md)
13+
## [Customize CMake settings](customize-cmake-settings.md)
14+
## [Configure CMake debugging sessions](configure-cmake-debugging-sessions.md)
1315
# [MSBuild Projects](creating-and-managing-visual-cpp-projects.md)
1416
## [Project Types in Visual C++](visual-cpp-project-types.md)
1517
## [Add New Item Templates in Visual C++](using-visual-cpp-add-new-item-templates.md)

docs/ide/cmake-tools-for-visual-cpp.md

Lines changed: 12 additions & 265 deletions
Large diffs are not rendered by default.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: "Configure CMake debugging sessions in Visual Studio"
3+
ms.date: "11/08/2018"
4+
helpviewer_keywords: ["CMake debugging"]
5+
---
6+
# Configure CMake debugging sessions
7+
8+
All executable CMake targets are shown in the **Startup Item** dropdown in the **General** toolbar. To start a debugging session, just select one and launch the debugger.
9+
10+
![CMake startup item dropdown](media/cmake-startup-item-dropdown.png "CMake startup item dropdown")
11+
12+
You can also start a debug session from the CMake menus.
13+
14+
To customize the debugger settings for any executable CMake target in your project, right-click on the specific CMakeLists.txt file and select **Debug and Launch Settings**. When you select a CMake target in the submenu, a file called launch.vs.json is created. This file is pre-populated with information about the CMake target you have selected and allows you to specify additional parameters such as program arguments or debugger type. To reference any key in a CMakeSettings.json file, preface it with `cmake.` in launch.vs.json. The following example shows a simple launch.vs.json file that pulls in the value of the `remoteCopySources` key in the CMakeSettings.json file for the currently selected configuration:
15+
16+
```json
17+
{
18+
"version": "0.2.1",
19+
"defaults": {},
20+
"configurations": [
21+
{
22+
"type": "default",
23+
"project": "CMakeLists.txt",
24+
"projectTarget": "CMakeHelloWorld.exe (Debug\\CMakeHelloWorld.exe)",
25+
"name": "CMakeHelloWorld.exe (Debug\\CMakeHelloWorld.exe)",
26+
"args": ["${cmake.remoteCopySources}"]
27+
}
28+
]
29+
}
30+
```
31+
32+
As soon as you save the launch.vs.json file, an entry is created in the **Startup Item** dropdown with the new name. By editing the launch.vs.json file, you can create as many debug configurations as you like for any number of CMake targets.
33+
34+
**Visual Studio 2017 version 15.4**: Launch.vs.json supports variables that are declared in CMakeSettings.json (see below) and that are applicable to the currently-selected configuration. It also has a key named `currentDir`, which sets the current directory of the launching app:
35+
36+
```json
37+
{
38+
"type": "default",
39+
"project": "CMakeLists.txt",
40+
"projectTarget": "CMakeHelloWorld1.exe (C:\\Users\\satyan\\CMakeBuilds\\Test\\Debug\\CMakeHelloWorld1.exe)",
41+
"name": "CMakeHelloWorld1.exe (C:\\Users\\satyan\\CMakeBuilds\\Test\\Debug\\CMakeHelloWorld1.exe)",
42+
"currentDir": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}"
43+
}
44+
```
45+
46+
When you run the app, the value of `currentDir` is something similar to
47+
48+
```cmd
49+
C:\Users\satyan\7f14809a-2626-873e-952e-cdf038211175\
50+
```
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
title: "Customize CMake settings in Visual Studio"
3+
ms.date: "11/08/2018"
4+
helpviewer_keywords: ["CMake settings"]
5+
---
6+
# Customizing CMake settings
7+
8+
By default, Visual Studio provides six default CMake configurations ("x86-Debug", "x86-Release", "x64-Debug", "x64-Release", "Linux-Debug" and "Linux-Release"). These configurations define how CMake.exe is invoked to create the CMake cache for a given project. To modify these configurations, or create a new custom configuration, choose **CMake | Change CMake Settings**, and then choose the CMakeLists.txt file that the settings apply to. The **Change CMake Settings** command is also available on the file's context menu in **Solution Explorer**. This command creates a CMakeSettings.json file in the project folder. This file is used to re-create the CMake cache file, for example after a **Clean** operation.
9+
10+
![CMake main menu command for change settings](media/cmake-change-settings.png)
11+
12+
JSON IntelliSense helps you edit the CMakeSettings.json file:
13+
14+
![CMake JSON IntelliSense](media/cmake-json-intellisense.png "CMake JSON IntelliSense")
15+
16+
The following example shows a sample configuration, which you can use as the starting point to create your own in CMakeSettings.json:
17+
18+
```json
19+
{
20+
"name": "x86-Debug",
21+
"generator": "Ninja",
22+
"configurationType": "Debug",
23+
"inheritEnvironments": [ "msvc_x86" ],
24+
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
25+
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
26+
"cmakeCommandArgs": "",
27+
"buildCommandArgs": "-v",
28+
"ctestCommandArgs": ""
29+
},
30+
31+
```
32+
33+
1. **name**: the name that appears in the C++ configuration dropdown. This property value can also be used as a macro, `${name}`, to specify other property values. For an example, see the **buildRoot** definition in CMakeSettings.json.
34+
35+
1. **generator**: maps to the **-G** switch and specifies the generator to be used. This property can also be used as a macro, `${generator}`, to help specify other property values. Visual Studio currently supports the following CMake generators:
36+
37+
- "Ninja"
38+
- "Visual Studio 14 2015"
39+
- "Visual Studio 14 2015 ARM"
40+
- "Visual Studio 14 2015 Win64"
41+
- "Visual Studio 15 2017"
42+
- "Visual Studio 15 2017 ARM"
43+
- "Visual Studio 15 2017 Win64"
44+
45+
Because Ninja is designed for fast build speeds instead of flexibility and function, it is set as the default. However, some CMake projects may be unable to correctly build using Ninja. If this occurs, you can instruct CMake to generate a Visual Studio project instead.
46+
47+
To specify a Visual Studio generator, open the CMakeSettings.json from the main menu by choosing **CMake | Change CMake Settings**. Delete “Ninja” and type “V”. This activates IntelliSense, which enables you to choose the generator you want.
48+
49+
1. **buildRoot**: maps to **-DCMAKE_BINARY_DIR** switch and specifies where the CMake cache will be created. If the folder does not exist, it is created.
50+
51+
1. **variables**: contains a name-value pair of CMake variables that will get passed as **-D** *_name_=_value_* to CMake. If your CMake project build instructions specify the addition of any variables directly to the CMake cache file, it is recommended that you add them here instead. The following example shows how to specify the name-value pairs:
52+
53+
```json
54+
"variables": [
55+
{
56+
"name": "CMAKE_CXX_COMPILER",
57+
"value": "C:/Program Files (x86)/Microsoft Visual Studio/157/Enterprise/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe"
58+
},
59+
{
60+
"name": "CMAKE_C_COMPILER",
61+
"value": "C:/Program Files (x86)/Microsoft Visual Studio/157/Enterprise/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe"
62+
}
63+
]
64+
```
65+
66+
1. **cmakeCommandArgs**: specifies any additional switches you want to pass to CMake.exe.
67+
68+
1. **configurationType**: defines the build configuration type for the selected generator. Currently supported values are "Debug", "MinSizeRel", "Release", and "RelWithDebInfo".
69+
70+
1. **ctestCommandArgs**: specifies additional switches to pass to CTest when running tests.
71+
72+
1. **buildCommandArgs**: specifies additional switches to pass to the underlying build system. For example, passing -v when using the Ninja generator forces Ninja to output command lines.
73+
74+
## Environment variables
75+
76+
CMakeSettings.json also supports consuming environment variables in any of the properties mentioned above. The syntax to use is `${env.FOO}` to expand the environment variable %FOO%.
77+
You also have access to built-in macros inside this file:
78+
79+
- `${workspaceRoot}` – provides the full path of the workspace folder
80+
- `${workspaceHash}` – hash of workspace location; useful for creating a unique identifier for the current workspace (for example, to use in folder paths)
81+
- `${projectFile}` – the full path of the root CMakeLists.txt file
82+
- `${projectDir}` – the full path of the folder of the root CMakeLists.txt file
83+
- `${thisFile}` – the full path of the CMakeSettings.json file
84+
- `${name}` – the name of the configuration
85+
- `${generator}` – the name of the CMake generator used in this configuration
86+
87+
## Ninja command line arguments
88+
89+
If targets are unspecified, builds the 'default' target (see manual).
90+
91+
```cmd
92+
C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise>ninja -?
93+
ninja: invalid option -- `-?'
94+
usage: ninja [options] [targets...]
95+
```
96+
97+
|Option|Description|
98+
|--------------|------------|
99+
| --version | print ninja version ("1.7.1")|
100+
| -C DIR | change to DIR before doing anything else|
101+
| -f FILE | specify input build file (default=build.ninja)|
102+
| -j N | run N jobs in parallel (default=14, derived from CPUs available)|
103+
| -k N | keep going until N jobs fail (default=1)|
104+
| -l N | do not start new jobs if the load average is greater than N|
105+
| -n | dry run (don't run commands but act like they succeeded)|
106+
| -v | show all command lines while building|
107+
| -d MODE | enable debugging (use -d list to list modes)|
108+
| -t TOOL | run a subtool (use -t list to list subtools). terminates toplevel options; further flags are passed to the tool|
109+
| -w FLAG | adjust warnings (use -w list to list warnings)|
110+
111+
## Inherited environments (Visual Studio 2017 version 15.5)
112+
113+
CMakeSettings.json now supports inherited environments. This feature enables you to (1) inherit default environments and (2) create custom environment variables that are passed to CMake.exe when it runs.
114+
115+
```json
116+
"inheritEnvironments": [ "msvc_x64_x64" ]
117+
```
118+
119+
The example above is the same as running the **Developer Command Prompt for VS 2017** with the **-arch=amd64 -host_arch=amd64** arguments.
120+
121+
The following table shows the default values:
122+
123+
|Context Name|Description|
124+
|-----------|-----------------|
125+
|vsdev|The default Visual Studio environment|
126+
|msvc_x86|Compile for x86 using x86 tools|
127+
|msvc_arm| Compile for ARM using x86 tools|
128+
|msvc_arm64|Compile for ARM64 using x86 tools|
129+
|msvc_x86_x64|Compile for AMD64 using x86 tools|
130+
|msvc_x64_x64|Compile for AMD64 using 64-bit tools|
131+
|msvc_arm_x64|Compile for ARM using 64-bit tools|
132+
|msvc_arm64_x64|Compile for ARM64 using 64-bit tools|
133+
134+
### Custom environment variables
135+
136+
In CMakeSettings.json, you can define custom environment variables globally or per-configuration in the **environments** property. The following example defines one global variable, **BuildDir**, which is inherited in both the x86-Debug and x64-Debug configurations. Each configuration uses the variable to specify the value for the **buildRoot** property for that configuration. Note also how each configuration uses the **inheritEnvironments** property to specify a variable that applies only to that configuration.
137+
138+
```json
139+
{
140+
// The "environments" property is an array of key value pairs of the form
141+
// { "EnvVar1": "Value1", "EnvVar2": "Value2" }
142+
"environments": [
143+
{
144+
"BuildDir": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build",
145+
}
146+
],
147+
148+
"configurations": [
149+
{
150+
"name": "x86-Debug",
151+
"generator": "Ninja",
152+
"configurationType": "Debug",
153+
// Inherit the defaults for using the MSVC x86 compiler.
154+
"inheritEnvironments": [ "msvc_x86" ],
155+
"buildRoot": "${env.BuildDir}\\${name}" },
156+
{
157+
"name": "x64-Debug",
158+
"generator": "Ninja",
159+
"configurationType": "Debug",
160+
// Inherit the defaults for using the MSVC x64 compiler.
161+
"inheritEnvironments": [ "msvc_x64" ],
162+
"buildRoot": "${env.BuildDir}\\${name}"
163+
}
164+
]
165+
}
166+
```
167+
168+
In the next example, the x86-Debug configuration defines its own value for the **BuildDir** property, and this value overrides the value set by the global **BuildDir** property so that **BuildRoot** evaluates to `D:\custom-builddir\x86-Debug`.
169+
170+
```json
171+
{
172+
"environments": [
173+
{
174+
"BuildDir": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}",
175+
}
176+
],
177+
178+
"configurations": [
179+
{
180+
"name": "x86-Debug",
181+
182+
// The syntax for this property is the same as the global one above.
183+
"environments": [
184+
{
185+
// Replace the global property entirely.
186+
"BuildDir": "D:\\custom-builddir",
187+
}
188+
],
189+
190+
"generator": "Ninja",
191+
"configurationType": "Debug",
192+
"inheritEnvironments": [ "msvc_x86" ],
193+
// Evaluates to "D:\custom-builddir\x86-Debug"
194+
"buildRoot": "${env.BuildDir}\\${name}"
195+
},
196+
{
197+
"name": "x64-Debug",
198+
199+
"generator": "Ninja",
200+
"configurationType": "Debug",
201+
"inheritEnvironments": [ "msvc_x64" ],
202+
// Since this configuration doesn’t modify BuildDir, it inherits
203+
// from the one defined globally.
204+
"buildRoot": "${env.BuildDir}\\${name}"
205+
}
206+
]
207+
}
208+
```

docs/linux/TOC.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# [Download, Install and Setup the Linux Development Workload](download-install-and-setup-the-linux-development-workload.md)
2-
# [Configure a Linux Project](configure-a-linux-project.md)
3-
# [Configure a Linux CMake Project](cmake-linux-project.md)
4-
# [Create a New Linux Project](create-a-new-linux-project.md)
5-
# [Connect to Your Remote Linux Computer](connect-to-your-remote-linux-computer.md)
6-
# [Deploy, Run, and Debug Your Linux Project](deploy-run-and-debug-your-linux-project.md)
1+
# [Download, install and set up the Linux Development workload](download-install-and-setup-the-linux-development-workload.md)
2+
# [Configure a Linux project](configure-a-linux-project.md)
3+
# [Configure a Linux CMake project](cmake-linux-project.md)
4+
# [Create a new Linux project](create-a-new-linux-project.md)
5+
# [Connect to your remote Linux computer](connect-to-your-remote-linux-computer.md)
6+
# [Deploy, run, and debug your Linux project](deploy-run-and-debug-your-linux-project.md)
77
# [Linux Project Property Page Reference](prop-pages-linux.md)
88
## [General Properties (Linux)](prop-pages/general-linux.md)
99
## [Debugging Properties (Linux)](prop-pages/debugging-linux.md)

0 commit comments

Comments
 (0)