Skip to content

Commit 1c3ee3d

Browse files
author
mikeblome
committed
additional edits
1 parent f6c0eb2 commit 1c3ee3d

File tree

2 files changed

+61
-41
lines changed

2 files changed

+61
-41
lines changed

docs/build/cmake-predefined-configuration-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CMake projects are supported in Visual Studio 2017 and later.
1313

1414
::: moniker-end
1515

16-
::: moniker range="vs-2017"
16+
::: moniker range=">=vs-2017"
1717

1818
In a CMake project, build configurations are stored in a CMakeSettings.json file. When you choose **Manage Configurations** from the build configuration dropdown in the main toolbar, a dialog appears that shows the default CMake configurations available in Visual Studio:
1919
- x86 Debug
@@ -27,7 +27,7 @@ In a CMake project, build configurations are stored in a CMakeSettings.json file
2727
- MinGW Debug
2828
- MinGW Release
2929

30-
When you choose a configuration, it is added to the CMakeSettings.json file in the project's root folder. You can then use it to build your project.
30+
When you choose a configuration, it is added to the *CMakeSettings.json* file in the project's root folder. You can then use it to build your project. For information about the configuration properties, see [CMakeSettings reference](cmakesettings-reference.md).
3131

3232

3333
## Linux predefined build configurations:

docs/build/cmakesettings-reference.md

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
---
22
title: "CMakeSettings.json schema reference"
3-
ms.date: "10/11/2019"
3+
ms.date: "10/14/2019"
44
helpviewer_keywords: ["CMake in Visual C++"]
55
ms.assetid: 444d50df-215e-4d31-933a-b41841f186f8
66
---
77
# CMakeSettings.json schema reference
88

9-
The **cmakesettings.json** file contains information that Visual Studio uses to construct the command-line arguments that it passes to cmake.exe for a specified *configuration*. You can add any number of pre-defined or custom configurations to the file. After adding a configuration, you can edit it directly or use the **CMake Settings editor** (Visual Studio 2019 and later). See [Customize CMake build settings in Visual Studio](customize-cmake-settings.md) for more information about the editor.
9+
::: moniker range="vs-2015"
10+
11+
CMake projects are supported in Visual Studio 2017 and later.
12+
13+
::: moniker-end
14+
15+
::: moniker range=">=vs-2017"
16+
17+
The **cmakesettings.json** file contains information that Visual Studio uses for IntelliSense and to construct the command-line arguments that it passes to cmake.exe for a specified *configuration* and compiler *environment*. A configuration specifies properties that apply to a specific platform and build-type, for example, `x86-Debug` or `Linux-Release`. Each configuration specifies an environment, which encapsulates information about the compiler toolset, for example MSVC, GCC, or Clang. CMake uses the command-line arguments to regenerate the root *CMakeCache.txt* file for the project. The values can be overridden in the *CMakeLists.txt* files.
18+
19+
You can add or remove configurations in the IDE and then edit them directly in the JSON file or use the **CMake Settings editor** (Visual Studio 2019 and later). You can switch between the configurations easily in the IDE to generate the various builds. See [Customize CMake build settings in Visual Studio](customize-cmake-settings.md) for more information.
1020

1121
## Configurations
1222

13-
The `configurations` array consists of objects that represent CMake configurations that apply to the CMakeLists.txt file in the same folder. You can use these objects to define multiple build configurations and conveniently switch between them in the IDE.
23+
The `configurations` array contains all the configurations for a CMake project. See [CMake predefined configuration reference](cmake-predefined-configuration-reference.md) for more information about the pre-defined configurations. You can add any number of pre-defined or custom configurations to the file.
1424

1525
A `configuration` has these properties:
1626

17-
- `name`: names the configuration.
27+
- `addressSDanitizerEnabled`: if `true` compiles the program with Address Sanitizer (Experimental on Windows). On linux compile with -fno-omit-frame-pointer and compiler optimization level -Os or -Oo for best results.
28+
- `addressSanitizerRuntimeFlags`: runtime flags passed to AddressSanitizer via the ASAN_OPTIONS environment variable. Format: flag1=value:flag2=value2.
29+
- `buildCommandArgs`: specifies native build switches passed to CMake after --build --. For example, passing -v when using the Ninja generator forces Ninja to output command lines. See [Ninja command line arguments](#ninja) for more information on Ninja commands.
30+
- `buildRoot`: specifies the directory in which CMake generates build scripts for the chosen generator. Maps to **-DCMAKE_BINARY_DIR** switch and specifies where the CMake cache will be created. If the folder does not exist, it is created. Supported macros include `${workspaceRoot}`, `${workspaceHash}`, `${projectFile}`, `${projectDir}`, `${thisFile}`, `${thisFileDir}`, `${name}`, `${generator}`, and `${env.VARIABLE}`.
31+
- `cacheGenerationCommand`: specifies a command line tool and arguments, for example *gencache.bat debug* to generate the cache. The command is run from the shell in the specified environment for the configuration when the user explicity requests regeneration, or a CMakeLists.txt or CMakeSettings.json file is modified.
32+
- `cacheRoot`: specifies the path to a CMake cache. This directory should contain an existing CMakeCache.txt file.
33+
- `clangTidyChecks`: comma-separated list of warnigns which will be passed to clang-tidy; wildcards are allowed and '-' prefix will remove checks.
34+
- `cmakeCommandArgs`: specifies additional command-line options passed to CMake when invoked to generate the cache.
35+
- `cmakeToolchain`: specifies the toolchain file. This is passed to CMake using -DCMAKE_TOOLCHAIN_FILE."
36+
- `codeAnalysisRuleset`: specifies the ruleset to use when running code analysis. This can be a full path or the file name of a ruleset file installed by Visual Studio.
37+
- `configurationType`: specifies the build type configuration for the selected generator. May be one of:
38+
39+
- Debug
40+
- Release
41+
- MinSizeRel
42+
- RelWithDebInfo
43+
44+
- `ctestCommandArgs`: specifies additional command-line options passed to CTest when running the tests."
1845
- `description`: description of this configuration that will appear in menus.
46+
- `enableClangTidyCodeAnalysis`: use Clang-Tidy for code analysis.
47+
- `enableMicrosoftCodeAnalysis`: use Microsoft code analysis tools for code analysis.
1948
- `generator`: specifies CMake generator to use for this configuration. May be one of:
2049

2150
**Visual Studio 2019 only:**
@@ -33,35 +62,22 @@ A `configuration` has these properties:
3362
- Unix Makefiles
3463
- Ninja
3564

36-
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.
65+
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.
3766

38-
To specify a Visual Studio generator in Visual Studio 2017, 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.
67+
To specify a Visual Studio generator in Visual Studio 2017, 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.
3968

40-
To specify a Visual Studio generator in Visual Studio 2019, right-click on the CMakeLists.txt file in **Solution Explorer** and choose **CMake Settings for project** > **Show Advanced Settings** > **CMake Generator**.
69+
To specify a Visual Studio generator in Visual Studio 2019, right-click on the CMakeLists.txt file in **Solution Explorer** and choose **CMake Settings for project** > **Show Advanced Settings** > **CMake Generator**.
4170

42-
When the active configuration specifies a Visual Studio generator, by default MSBuild.exe is invoked with `-m -v:minimal` arguments. To customize the build, inside the `CMakeSettings.json` file, you can specify additional [MSBuild command line arguments](../build/reference/msbuild-visual-cpp-overview.md) to be passed to the build system via the `buildCommandArgs` property:
71+
When the active configuration specifies a Visual Studio generator, by default MSBuild.exe is invoked with `-m -v:minimal` arguments. To customize the build, inside the `CMakeSettings.json` file, you can specify additional [MSBuild command line arguments](../build/reference/msbuild-visual-cpp-overview.md) to be passed to the build system via the `buildCommandArgs` property:
4372

4473
```json
4574
"buildCommandArgs": "-m:8 -v:minimal -p:PreferredToolArchitecture=x64"
4675
```
4776

48-
- `configurationType`: specifies the build type configuration for the selected generator. May be one of:
49-
50-
- Debug
51-
- Release
52-
- MinSizeRel
53-
- RelWithDebInfo
54-
55-
- `inheritEnvironments`: specifies one or more compiler environments that this configuration depends on. May be any custom environment or one of the predefined environments.
56-
- `buildRoot`: specifies the directory in which CMake generates build scripts for the chosen generator. Maps to **-DCMAKE_BINARY_DIR** switch and specifies where the CMake cache will be created. If the folder does not exist, it is created.Supported macros include `${workspaceRoot}`, `${workspaceHash}`, `${projectFile}`, `${projectDir}`, `${thisFile}`, `${thisFileDir}`, `${name}`, `${generator}`, `${env.VARIABLE}`.
77+
- `inheritEnvironments`: specifies one or more compiler environments that this configuration depends on. May be any custom environment or one of the predefined environments. For more information, see [Environments](#environments).
5778
- `installRoot`: specifies the directory in which CMake generates install targets for the chosen generator. Supported macros include `${workspaceRoot}`, `${workspaceHash}`, `${projectFile}`, `${projectDir}`, `${thisFile}`, `${thisFileDir}`, `${name}`, `${generator}`, `${env.VARIABLE}`.
58-
- `cmakeCommandArgs`: specifies additional command-line options passed to CMake when invoked to generate the cache.
59-
- `cmakeToolchain`: specifies the toolchain file. This is passed to CMake using -DCMAKE_TOOLCHAIN_FILE."
60-
- `buildCommandArgs`: specifies native build switches passed to CMake after --build --. For example, passing -v when using the Ninja generator forces Ninja to output command lines. See [Ninja command line arguments](#ninja) for more information on Ninja commands.
61-
- `ctestCommandArgs`: specifies additional command-line options passed to CTest when running the tests."
62-
- `codeAnalysisRuleset`: specifies the ruleset to use when running code analysis. This can be a full path or the file name of a ruleset file installed by Visual Studio.
6379
- `intelliSenseMode`: specifies the mode used for computing intellisense information". May be one of:
64-
80+
6581
- windows-msvc-x86
6682
- windows-msvc-x64
6783
- windows-msvc-arm
@@ -82,7 +98,8 @@ When the active configuration specifies a Visual Studio generator, by default MS
8298
- linux-gcc-x64
8399
- linux-gcc-arm"
84100

85-
- `cacheRoot`: specifies the path to a CMake cache. This directory should contain an existing CMakeCache.txt file.
101+
- `name`: names the configuration. See [CMake predefined configuration reference](cmake-predefined-configuration-reference.md) for more information about the pre-defined configurations.
102+
- `wslPath`: the path to the launcher of an instance of Windows Subsystem for Linux
86103

87104
### Additional settings for CMake Linux projects.
88105

@@ -120,9 +137,9 @@ When the active configuration specifies a Visual Studio generator, by default MS
120137

121138
Note that if you do not define the `"type"`, the `"STRING"` type will be assumed by default.
122139

123-
## Environments and macros
140+
## <a name="environments"></a> Environments
124141

125-
An *environment* is a Visual Studio construct that encapsulates the environment variables that are set in the process that Visual Studio uses to invoke cmake.exe. You can use these variables to specify paths and other settings. For MSVC projects, the variables are those that are set in a [developer command prompt](building-on-the-command-line.md) for a specific platform. For example, the `msvc_x64_x64` environment is the same as running the **Developer Command Prompt for VS 2017** or **Developer Command Prompt for VS 2019** with the **-arch=amd64 -host_arch=amd64** arguments. The following predefined environments are provided:
142+
An *environment* encapsulates the environment variables that are set in the process that Visual Studio uses to invoke cmake.exe. For MSVC projects, the variables are those that are set in a [developer command prompt](building-on-the-command-line.md) for a specific platform. For example, the `msvc_x64_x64` environment is the same as running the **Developer Command Prompt for VS 2017** or **Developer Command Prompt for VS 2019** with the **-arch=amd64 -host_arch=amd64** arguments. You can use the `env.{<variable_name>}` syntax in *CMakeSettings.json* to reference the individual environment variables, for example to construct paths to folders. The following predefined environments are provided:
126143

127144
- linux_arm: Target ARM Linux remotely.
128145
- linux_x64: Target x64 Linux remotely.
@@ -136,19 +153,7 @@ An *environment* is a Visual Studio construct that encapsulates the environment
136153
- msvc_x86: Target x86 Windows with the MSVC compiler.
137154
- msvc_x86_x64: Target x86 Windows with the 64-bit MSVC compiler.
138155

139-
In addition to the environments, the following macros are also provided:
140-
141-
- `${workspaceRoot}` – the full path of the workspace folder
142-
- `${workspaceHash}` – hash of workspace location; useful for creating a unique identifier for the current workspace (for example, to use in folder paths)
143-
- `${projectFile}` – the full path of the root CMakeLists.txt file
144-
- `${projectDir}` – the full path of the folder of the root CMakeLists.txt file
145-
- `${thisFile}` – the full path of the `CMakeSettings.json` file
146-
- `${name}` – the name of the configuration
147-
- `${generator}` – the name of the CMake generator used in this configuration
148-
149-
All references to macros and environment variables in *CMakeSettings.json* are expanded before being passed to the cmake command line.
150-
151-
## Accessing environment variables from CMakeLists.txt
156+
### Accessing environment variables from CMakeLists.txt
152157

153158
From a CMakeLists.txt file, all environment variables are referenced by the syntax `$ENV{variable_name}`. To see the available variables for an environment, open the corresponding command prompt and type `SET`. Some of the information in environment variables is also available through CMake system introspection variables, but you may find it more convenient to use the environment variable. For example, the MSVC compiler version or Windows SDK version are easily retrieved through the environment variables.
154159

@@ -236,6 +241,19 @@ In the next example, the x86-Debug configuration defines its own value for the *
236241
]
237242
}
238243
```
244+
## Macros
245+
246+
The following macros can be used in *CMakeSettings.json*:
247+
248+
- `${workspaceRoot}` – the full path of the workspace folder
249+
- `${workspaceHash}` – hash of workspace location; useful for creating a unique identifier for the current workspace (for example, to use in folder paths)
250+
- `${projectFile}` – the full path of the root CMakeLists.txt file
251+
- `${projectDir}` – the full path of the folder of the root CMakeLists.txt file
252+
- `${thisFile}` – the full path of the `CMakeSettings.json` file
253+
- `${name}` – the name of the configuration
254+
- `${generator}` – the name of the CMake generator used in this configuration
255+
256+
All references to macros and environment variables in *CMakeSettings.json* are expanded before being passed to the cmake.exe command line.
239257

240258
## <a name="ninja"></a> Ninja command line arguments
241259

@@ -260,3 +278,5 @@ usage: ninja [options] [targets...]
260278
| -d MODE | enable debugging (use -d list to list modes)|
261279
| -t TOOL | run a subtool (use -t list to list subtools). terminates top-level options; further flags are passed to the tool|
262280
| -w FLAG | adjust warnings (use -w list to list warnings)|
281+
282+
::: moniker-end

0 commit comments

Comments
 (0)