close
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/build/cmake-presets-vs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: "Reference for using CMake Presets to configure and build CMake pro
ms.date: 06/09/2023
ms.topic: reference
ms.custom: sfi-image-nochange
ai-usage: ai-assisted
---

# Configure and build with CMake Presets in Visual Studio
Expand Down Expand Up @@ -460,6 +461,38 @@ The `<additional-options>` part lists other compilation flags, like `"-fno-omit-

Pass runtime flags to AddressSanitizer by using the `ASAN_OPTIONS` field in *`launch.vs.json`*. `ASAN_OPTIONS` defaults to `detect_leaks=0` when no other runtime options are specified because LeakSanitizer isn't supported in Visual Studio.

## Enable Segment Heap

The Segment Heap is a Windows heap implementation that reduces memory usage and fragmentation. Visual Studio ships a CMake script that enables Segment Heap for your project by adding the required manifest settings. New C++ CMake projects enable Segment Heap by default.

To enable Segment Heap, set `CMAKE_PROJECT_TOP_LEVEL_INCLUDES` in the `cacheVariables` map of your Configure Preset in *`CMakePresets.json`*. Optionally, set the `VS_SEGMENT_HEAP_ALLOWLIST` and `VS_SEGMENT_HEAP_EXCLUDE` environment variables to control which targets in the project use Segment Heap. Separate target names with semicolons:

```json
{
"configurePresets": [
{
// ...
"environment": {
"VS_SEGMENT_HEAP_ALLOWLIST": "target1;target2;",
"VS_SEGMENT_HEAP_EXCLUDE": "target3;"
},
"cacheVariables": {
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
}
}
]
}

```

> [!NOTE]
> `CMAKE_PROJECT_TOP_LEVEL_INCLUDES` is available in CMake 3.24 or later.

- `VS_SEGMENT_HEAP_ALLOWLIST` — Apply the Segment Heap manifest entry only to the listed targets. Exclude all other targets.
- `VS_SEGMENT_HEAP_EXCLUDE` — Exclude the listed targets from using the Segment Heap.

In this example, `CMAKE_PROJECT_TOP_LEVEL_INCLUDES` points to the Visual Studio-provided `SegmentHeap.cmake` script. The optional `VS_SEGMENT_HEAP_ALLOWLIST` and `VS_SEGMENT_HEAP_EXCLUDE` variables show how to include or exclude specific targets. If neither variable is set, Visual Studio enables Segment Heap for all targets. If both variables are set, `VS_SEGMENT_HEAP_ALLOWLIST` takes precedence.

## Run CMake from the command line or a CI pipeline

You can use the same *`CMakePresets.json`* and *`CMakeUserPresets.json`* files to invoke CMake in Visual Studio and from the command line. The [CMake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) and [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) documentation are the best resources for invoking CMake and CTest with `--preset`. CMake version 3.20 or later is required.
Expand Down
5 changes: 5 additions & 0 deletions docs/build/reference/manifest-tool-property-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ f1_keywords:
- VC.Project.VCManifestTool.ReplacementsFile
- VC.Project.VCManifestTool.UpdateFileHashes
- VC.Project.VCManifestTool.UpdateFileHashesSearchPath
- VC.Project.VCManifestTool.EnableSegmentHeap
---
# Manifest Tool Property Pages

Expand Down Expand Up @@ -97,6 +98,10 @@ Specifies whether the application is DPI-aware. By default, the setting is **Yes
- **High DPI Aware**
- **Per Monitor High DPI Aware**

### Segment Heap

Specifies whether the application utilizes the Segment Heap. When enabled, applications benefit from improved memory efficiency, reduced fragmentation, and enhanced memory security. For new C++ projects, the setting is **Yes** by default.

## Isolated COM Property Page

For more information about isolated COM, see [Isolated applications](/windows/win32/SbsCs/isolated-applications) and [How to: Build isolated applications to consume COM components](../how-to-build-isolated-applications-to-consume-com-components.md).
Expand Down