Skip to content

Commit 45842d5

Browse files
nikita-karatunhanniavaleragcampbell-msftsnehara99Copilot
authored
Set Build Target Same As Launch Target feature (#4519)
* Set Build Target Same As Launch Target feature * Leverage selectBuildAndLaunchTarget, update docs and changelog - selectLaunchTarget delegates to selectBuildAndLaunchTarget when cmake.setBuildTargetSameAsLaunchTarget is enabled - Remove redundant auto-sync from setLaunchTargetName - Update setting description to mention debug target - Add missing docs entry in cmake-settings.md - Add changelog entry for PR #4519 Co-authored-by: Copilot <[email protected]> * Remove trailing commas in config emitters and test fixture Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Hannia Valera <[email protected]> Co-authored-by: Garrett Campbell <[email protected]> Co-authored-by: snehara99 <[email protected]> Co-authored-by: Sneha Ramachandran <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent aca01d1 commit 45842d5

7 files changed

Lines changed: 29 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Features:
88
- Add individual CTest test nodes to the Project Outline with inline run/debug buttons, and enable debugging tests from both the Outline and Test Explorer without requiring a launch.json. [#4721](https://github.com/microsoft/vscode-cmake-tools/pull/4721)
99
- Add "Delete Cache, Reconfigure and Build" command that chains cache deletion, reconfiguration, and build into a single action. [#4723](https://github.com/microsoft/vscode-cmake-tools/pull/4723)
1010
- Add "Set Build and Launch/Debug Target" command that sets both the build target and launch target simultaneously. [#4732](https://github.com/microsoft/vscode-cmake-tools/pull/4732)
11+
- Add `cmake.setBuildTargetSameAsLaunchTarget` setting to automatically set the build target when the launch/debug target is changed. [#4519](https://github.com/microsoft/vscode-cmake-tools/pull/4519) [@nikita-karatun](https://github.com/nikita-karatun)
1112
- Add `cmake.additionalBuildProblemMatchers` setting to define custom problem matchers for build output. Supports tools like clang-tidy, PCLint Plus, cppcheck, or custom scripts integrated via `add_custom_command`/`add_custom_target`. [#4077](https://github.com/microsoft/vscode-cmake-tools/issues/4077)
1213

1314
Improvements:

docs/cmake-settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Options that support substitution, in the table below, allow variable references
7676
| `cmake.preRunCoverageTarget` | Target to build before running tests with coverage using the test explorer. | `null` | no |
7777
| `cmake.revealLog` | Controls when the CMake output log should be revealed. | `always` | no |
7878
| `cmake.saveBeforeBuild` | If `true` (the default), saves open text documents when build or configure is invoked before running CMake. | `true` | no |
79+
| `cmake.setBuildTargetSameAsLaunchTarget` | If `true`, setting the launch/debug target automatically sets the build target to match. | `false` | no |
7980
| `cmake.setBuildTypeOnMultiConfig` | If `true`, set build type on multi-config generators. | `false` | no |
8081
| `cmake.showConfigureWithDebuggerNotification` | If `true`, show notification when configure with debugger. | `true` | no |
8182
| `cmake.showNotAllDocumentsSavedQuestion` | If `true`, show not all documents saved question. | `true` | no |

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4014,6 +4014,12 @@
40144014
"default": false,
40154015
"description": "%cmake-tools.configuration.cmake.useFolderPropertyInBuildTargetDropdown.description%",
40164016
"scope": "resource"
4017+
},
4018+
"cmake.setBuildTargetSameAsLaunchTarget": {
4019+
"type": "boolean",
4020+
"default": false,
4021+
"description": "%cmake-tools.configuration.cmake.setBuildTargetSameAsLaunchTarget.description%",
4022+
"scope": "resource"
40174023
}
40184024
}
40194025
},

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
"cmake-tools.configuration.cmake.postRunCoverageTarget.description": "Target to build after running tests with coverage using the test explorer",
375375
"cmake-tools.configuration.cmake.coverageInfoFiles.description": "LCOV coverage info files to be processed after running tests with coverage using the test explorer.",
376376
"cmake-tools.configuration.cmake.useFolderPropertyInBuildTargetDropdown.description": "Controls if the default build target dropdown is grouped by the CMake folder groups.",
377+
"cmake-tools.configuration.cmake.setBuildTargetSameAsLaunchTarget.description": "When enabled, setting the launch/debug target automatically sets the build target to match. The build target can still be changed independently.",
377378
"cmake-tools.debugger.pipeName.description": "Name of the pipe (on Windows) or domain socket (on Unix) to use for debugger communication.",
378379
"cmake-tools.debugger.clean.description": "Clean prior to configuring.",
379380
"cmake-tools.debugger.configureAll.description": "Configure for all projects.",

src/cmakeProject.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,14 +2636,19 @@ export class CMakeProject {
26362636

26372637
/**
26382638
* Implementation of `cmake.selectLaunchTarget`
2639+
* When cmake.setBuildTargetSameAsLaunchTarget is true, delegates to
2640+
* selectBuildAndLaunchTarget so the build target is also updated.
26392641
*/
26402642
async selectLaunchTarget(name?: string): Promise<string | null> {
2643+
if (this.workspaceContext.config.setBuildTargetSameAsLaunchTarget) {
2644+
return this.selectBuildAndLaunchTarget(name);
2645+
}
26412646
return this.setLaunchTargetByName(name);
26422647
}
26432648

26442649
/**
26452650
* Implementation of `cmake.selectBuildAndLaunchTarget`
2646-
* Sets both the build target and the launch target simultaneously.
2651+
* Sets both the build target and the launch/debug target simultaneously.
26472652
*/
26482653
async selectBuildAndLaunchTarget(name?: string): Promise<string | null> {
26492654
const result = await this.setLaunchTargetByName(name);
@@ -2671,8 +2676,7 @@ export class CMakeProject {
26712676
return null;
26722677
} if (executableTargets.length === 1) {
26732678
const target = executableTargets[0];
2674-
await this.workspaceContext.state.setLaunchTargetName(this.folderName, target.name, this.isMultiProjectFolder);
2675-
this._launchTargetName.set(target.name);
2679+
await this.setLaunchTargetName(target.name);
26762680
return target.path;
26772681
}
26782682

@@ -2690,11 +2694,15 @@ export class CMakeProject {
26902694
if (!chosen) {
26912695
return null;
26922696
}
2693-
await this.workspaceContext.state.setLaunchTargetName(this.folderName, chosen.label, this.isMultiProjectFolder);
2694-
this._launchTargetName.set(chosen.label);
2697+
await this.setLaunchTargetName(chosen.label);
26952698
return chosen.detail;
26962699
}
26972700

2701+
private async setLaunchTargetName(name: string) {
2702+
await this.workspaceContext.state.setLaunchTargetName(this.folderName, name, this.isMultiProjectFolder);
2703+
this._launchTargetName.set(name);
2704+
}
2705+
26982706
async getCurrentLaunchTarget(): Promise<ExecutableTarget | null> {
26992707
const targetName = this.workspaceContext.state.getLaunchTargetName(this.folderName, this.isMultiProjectFolder);
27002708
const target = (await this.executableTargets).find(e => e.name === targetName);

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export interface ExtensionConfigurationSettings {
235235
postRunCoverageTarget: string | null;
236236
coverageInfoFiles: string[];
237237
useFolderPropertyInBuildTargetDropdown: boolean;
238+
setBuildTargetSameAsLaunchTarget: boolean;
238239
additionalBuildProblemMatchers: BuildProblemMatcherConfig[];
239240
}
240241

@@ -627,6 +628,10 @@ export class ConfigurationReader implements vscode.Disposable {
627628
return this.configData.useFolderPropertyInBuildTargetDropdown;
628629
}
629630

631+
get setBuildTargetSameAsLaunchTarget(): boolean {
632+
return this.configData.setBuildTargetSameAsLaunchTarget;
633+
}
634+
630635
private readonly emitters: EmittersOf<ExtensionConfigurationSettings> = {
631636
autoSelectActiveFolder: new vscode.EventEmitter<boolean>(),
632637
defaultActiveFolder: new vscode.EventEmitter<string | null>(),
@@ -698,6 +703,7 @@ export class ConfigurationReader implements vscode.Disposable {
698703
postRunCoverageTarget: new vscode.EventEmitter<string | null>(),
699704
coverageInfoFiles: new vscode.EventEmitter<string[]>(),
700705
useFolderPropertyInBuildTargetDropdown: new vscode.EventEmitter<boolean>(),
706+
setBuildTargetSameAsLaunchTarget: new vscode.EventEmitter<boolean>(),
701707
additionalBuildProblemMatchers: new vscode.EventEmitter<BuildProblemMatcherConfig[]>()
702708
};
703709

test/unit-tests/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
8686
postRunCoverageTarget: null,
8787
coverageInfoFiles: [],
8888
useFolderPropertyInBuildTargetDropdown: true,
89+
setBuildTargetSameAsLaunchTarget: false,
8990
additionalBuildProblemMatchers: []
9091
});
9192
ret.updatePartial(conf);

0 commit comments

Comments
 (0)