in src/cmake-tools.ts [707:804]
private async _startNewCMakeDriver(cmake: CMakeExecutable): Promise<CMakeDriver> {
log.debug(localize('starting.cmake.driver', 'Starting CMake driver'));
if (!cmake.isPresent) {
throw new Error(localize('bad.cmake.executable', 'Bad CMake executable {0}.', `"${cmake.path}"`));
}
const workspace = this.folder.uri.fsPath;
let drv: CMakeDriver;
const preferredGenerators = this.getPreferredGenerators();
const preConditionHandler = async (e: CMakePreconditionProblems, config?: ConfigurationReader) => this.cmakePreConditionProblemHandler(e, true, config);
let communicationMode = this.workspaceContext.config.cmakeCommunicationMode.toLowerCase();
const fileApi = 'fileapi';
const serverApi = 'serverapi';
const legacy = 'legacy';
if (communicationMode !== fileApi && communicationMode !== serverApi && communicationMode !== legacy) {
if (cmake.isFileApiModeSupported) {
communicationMode = fileApi;
} else if (cmake.isServerModeSupported) {
communicationMode = serverApi;
} else {
communicationMode = legacy;
}
} else if (communicationMode === fileApi) {
if (!cmake.isFileApiModeSupported) {
if (cmake.isServerModeSupported) {
communicationMode = serverApi;
log.warning(
localize('switch.to.serverapi',
'CMake file-api communication mode is not supported in versions earlier than {0}. Switching to CMake server communication mode.',
versionToString(cmake.minimalFileApiModeVersion)));
} else {
communicationMode = legacy;
}
}
}
if (communicationMode !== fileApi && communicationMode !== serverApi) {
log.warning(
localize('please.upgrade.cmake',
'For the best experience, CMake server or file-api support is required. Please upgrade CMake to {0} or newer.',
versionToString(cmake.minimalServerModeVersion)));
}
try {
if (communicationMode === serverApi) {
this._statusMessage.set(localize('starting.cmake.driver.status', 'Starting CMake Server...'));
}
switch (communicationMode) {
case fileApi:
drv = await CMakeFileApiDriver.create(cmake, this.workspaceContext.config,
this.useCMakePresets,
this.activeKit,
this.configurePreset,
this.buildPreset,
this.testPreset,
workspace,
preConditionHandler,
preferredGenerators);
break;
case serverApi:
drv = await CMakeServerClientDriver.create(cmake,
this.workspaceContext.config,
this.useCMakePresets,
this.activeKit,
this.configurePreset,
this.buildPreset,
this.testPreset,
workspace,
preConditionHandler,
preferredGenerators);
break;
default:
drv = await LegacyCMakeDriver.create(cmake,
this.workspaceContext.config,
this.useCMakePresets,
this.activeKit,
this.configurePreset,
this.buildPreset,
this.testPreset,
workspace,
preConditionHandler,
preferredGenerators);
}
} finally {
this._statusMessage.set(localize('ready.status', 'Ready'));
}
await drv.setVariant(this._variantManager.activeVariantOptions, this._variantManager.activeKeywordSetting);
this._targetName.set(this.defaultBuildTarget || (this.useCMakePresets ? this._targetsInPresetName : drv.allTargetName));
await this._ctestController.reloadTests(drv);
// Update the task provider when a new driver is created
updateCMakeDriverInTaskProvider(drv);
// All set up. Fulfill the driver promise.
return drv;
}