Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/cmake-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Options that support substitution, in the table below, allow variable references
| `cmake.configureOnOpen` | Automatically configure CMake project directories when they are opened. | `true` | no |
| `cmake.configureSettings` | An object containing `key:value` pairs, which will be passed to CMake when configuring. The same as passing `-DVAR_NAME=ON` via `cmake.configureArgs`. NOTE: If you are setting an array argument within `cmake.configureSettings`, you should use array notation, i.e. `"CONFIGURE_SETTINGS_LIST": [ "a", "b" ]` | `{}` (no values) | yes |
| `cmake.copyCompileCommands`| If not `null`, copies the `compile_commands.json` file generated by CMake to the path specified by this setting whenever CMake successfully configures. | `null` (do not copy the file) | yes |
| `cmake.postConfigureTask`| If not `null`, the task with this name is executed whenever CMake successfully configures. | `null` (do not run any task) | yes |
| `cmake.coverageInfoFiles` | LCOV coverage info files to be processed after running tests with coverage using the test explorer. | `[]` | yes |
| `cmake.cpackArgs` | An array of additional arguments to pass to cpack. | `[]` | yes |
| `cmake.cpackEnvironment` | An object containing `key:value` pairs of environment variables, which will be available when running cpack. | `{}` | yes |
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,12 @@
"description": "%cmake-tools.configuration.cmake.copyCompileCommands.description%",
"scope": "resource"
},
"cmake.postConfigureTask": {
"type": "string",
"default": null,
"description": "%cmake-tools.configuration.cmake.postConfigureTask.description%",
"scope": "resource"
},
"cmake.configureOnOpen": {
"type": "boolean",
"default": true,
Expand Down
32 changes: 32 additions & 0 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,36 @@ export class CMakeProject {
return;
}
}

}

/**
* Execute the postConfigureTask if configured
*/
private async executePostConfigureTask(): Promise<void> {
const postConfigureTask = this.workspaceContext.config.postConfigureTask;
if (postConfigureTask) {
try {
log.debug(localize('executing.post.configure.task', 'Executing post configure task: {0}', postConfigureTask));

// Fetch all available tasks
const tasks = await vscode.tasks.fetchTasks();

// Find the task by label
const task = tasks.find(t => t.name === postConfigureTask);

if (task) {
await vscode.tasks.executeTask(task);
} else {
const errorMsg = localize('task.not.found', 'Task "{0}" not found. Available tasks: {1}', postConfigureTask, tasks.map(t => t.name).join(', '));
void vscode.window.showErrorMessage(errorMsg);
log.error(errorMsg);
}
} catch (error: any) {
void vscode.window.showErrorMessage(localize('failed.to.execute.post.configure.task', 'Failed to execute post configure task: {0}', error.toString()));
log.error(localize('post.configure.task.error', 'Error executing post configure task'), error);
}
}
}

/**
Expand All @@ -1635,6 +1665,7 @@ export class CMakeProject {
const result: ConfigureResult = await drv.configure(trigger, []);
if (result.exitCode === 0) {
await this.refreshCompileDatabase(drv.expansionOptions);
await this.executePostConfigureTask();
} else {
log.showChannel(true);
}
Expand Down Expand Up @@ -1736,6 +1767,7 @@ export class CMakeProject {
if (result.exitCode === 0) {
await enableFullFeatureSet(true);
await this.refreshCompileDatabase(drv.expansionOptions);
await this.executePostConfigureTask();
} else if (result.exitCode !== 0 && (await this.getCMakeExecutable()).isDebuggerSupported && cmakeConfiguration.get(showDebuggerConfigurationString) && !forciblyCanceled && !cancelInformation.canceled && result.resultType === ConfigureResultType.NormalOperation) {
log.showChannel(true);
const yesButtonTitle: string = localize(
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export interface ExtensionConfigurationSettings {
emscriptenSearchDirs: string[];
mergedCompileCommands: string | null;
copyCompileCommands: string | null;
postConfigureTask: string | null;
loadCompileCommands: boolean;
configureOnOpen: boolean;
configureOnEdit: boolean;
Expand Down Expand Up @@ -535,6 +536,9 @@ export class ConfigurationReader implements vscode.Disposable {
get copyCompileCommands(): string | null {
return this.configData.copyCompileCommands;
}
get postConfigureTask(): string | null {
return this.configData.postConfigureTask;
}
get loadCompileCommands(): boolean {
return this.configData.loadCompileCommands;
}
Expand Down Expand Up @@ -642,6 +646,7 @@ export class ConfigurationReader implements vscode.Disposable {
emscriptenSearchDirs: new vscode.EventEmitter<string[]>(),
mergedCompileCommands: new vscode.EventEmitter<string | null>(),
copyCompileCommands: new vscode.EventEmitter<string | null>(),
postConfigureTask: new vscode.EventEmitter<string | null>(),
loadCompileCommands: new vscode.EventEmitter<boolean>(),
configureOnOpen: new vscode.EventEmitter<boolean>(),
configureOnEdit: new vscode.EventEmitter<boolean>(),
Expand Down
3 changes: 2 additions & 1 deletion test/unit-tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
preRunCoverageTarget: null,
postRunCoverageTarget: null,
coverageInfoFiles: [],
useFolderPropertyInBuildTargetDropdown: true
useFolderPropertyInBuildTargetDropdown: true,
postConfigureTask: null
});
ret.updatePartial(conf);
return ret;
Expand Down