Skip to content

Commit ae3da88

Browse files
Fix: CMake: Set Build Target shows all targets when using presets (#4671)
* Initial plan * Fix CMake: Set Build Target command not showing available targets with presets When using CMake Presets with build presets that define a targets field, the showTargetSelector() method was returning early and only showing preset-defined targets instead of all available CMake targets. This fix removes the early return and instead adds the [Targets In Preset] option to the beginning of the full target list when appropriate. Users can now see and select from all available CMake targets, while still having the option to use [Targets In Preset] to build the preset-defined targets. Fixes #4509 Co-authored-by: hanniavalera <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hanniavalera <[email protected]>
1 parent 595d649 commit ae3da88

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Bug Fixes:
7373
- Fix build/debug/launch target selection not working when `CMAKE_BUILD_TYPE` is not set in the preset or is changed in CMakeLists.txt. [#4219](https://github.com/microsoft/vscode-cmake-tools/issues/4219)
7474
- Fix CMake script path links not working in CHS/CSY/FRA/PLK locales due to localized quotes. [#4383](https://github.com/microsoft/vscode-cmake-tools/issues/4383)
7575
- Fix user-level tasks defined in `~/.config/Code/User/tasks.json` causing infinite spinner. [#4659](https://github.com/microsoft/vscode-cmake-tools/pull/4659)
76+
- Fix `CMake: Set Build Target` command not showing available targets when using presets with defined targets. [#4509](https://github.com/microsoft/vscode-cmake-tools/issues/4509)
7677
- Fix `cmake.compileFile` failing to find compilation info when using presets without `CMAKE_EXPORT_COMPILE_COMMANDS`. [#4484](https://github.com/microsoft/vscode-cmake-tools/issues/4484)
7778
- Fix "Copy Value" in CMake debugger copying variable name instead of value. [#4551](https://github.com/microsoft/vscode-cmake-tools/issues/4551)
7879
- cmakeDriver: Fixes getCompilerVersion by using compilerPath instead of compilerName. [#4647](https://github.com/microsoft/vscode-cmake-tools/pull/4647) [@lygstate](https://github.com/lygstate)

src/cmakeProject.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,19 +2408,17 @@ export class CMakeProject {
24082408
return '';
24092409
}
24102410

2411-
if (this.useCMakePresets && this.buildPreset?.targets) {
2412-
const targets = [this.targetsInPresetName];
2413-
targets.push(...(util.isString(this.buildPreset.targets) ? [this.buildPreset.targets] : this.buildPreset.targets));
2414-
const sel = await vscode.window.showQuickPick(targets, { placeHolder: localize('select.active.target.tooltip', 'Select the default build target') });
2415-
return sel || null;
2416-
}
2417-
24182411
if (!drv.targets.length) {
24192412
return await vscode.window.showInputBox({ prompt: localize('enter.target.name', 'Enter a target name') }) || null;
24202413
} else {
24212414
const folders: string[] = [];
24222415
const itemsGroup: (RichTarget | NamedTarget | FolderTarget)[] = [];
24232416

2417+
// Add special "[Targets In Preset]" option when using presets with defined targets
2418+
if (this.useCMakePresets && this.buildPreset?.targets) {
2419+
itemsGroup.push({ type: 'named', name: this.targetsInPresetName });
2420+
}
2421+
24242422
// group the data
24252423
drv.uniqueTargets.forEach((t) => {
24262424
switch (t.type) {

0 commit comments

Comments
 (0)