in src/cpptools.ts [425:481]
private _buildConfigurationData(fileGroup: codemodel_api.CodeModelFileGroup, opts: codemodel_api.CodeModelParams, target: TargetDefaults, sysroot: string): cpt.SourceFileConfiguration {
// If the file didn't have a language, default to C++
const lang = fileGroup.language === "RC" ? undefined : fileGroup.language;
// First try to get toolchain values directly reported by CMake. Check the
// group's language compiler, then the C++ compiler, then the C compiler.
const comp_toolchains: codemodel_api.CodeModelToolchain | undefined = opts.codeModelContent.toolchains?.get(lang ?? "")
|| opts.codeModelContent.toolchains?.get('CXX')
|| opts.codeModelContent.toolchains?.get('C');
// If none of those work, fall back to the same order, but in the cache.
const comp_cache = opts.cache.get(`CMAKE_${lang}_COMPILER`)
|| opts.cache.get('CMAKE_CXX_COMPILER')
|| opts.cache.get('CMAKE_C_COMPILER');
// Try to get the path to the compiler we want to use
const comp_path = comp_toolchains ? comp_toolchains.path : (comp_cache ? comp_cache.as<string>() : opts.clCompilerPath);
if (!comp_path) {
throw new MissingCompilerException();
}
const targetFromToolchains = comp_toolchains?.target;
const targetArchFromToolchains = targetFromToolchains ? parseTargetArch(targetFromToolchains) : undefined;
const normalizedCompilerPath = util.platformNormalizePath(comp_path);
const flags = fileGroup.compileFlags ? [...shlex.split(fileGroup.compileFlags)] : target.compileFlags;
const { standard, extraDefinitions, targetArch } = parseCompileFlags(this.cpptoolsVersion, flags, lang);
const defines = (fileGroup.defines || target.defines).concat(extraDefinitions);
const includePath = fileGroup.includePath ? fileGroup.includePath.map(p => p.path) : target.includePath;
const normalizedIncludePath = includePath.map(p => util.platformNormalizePath(p));
const newBrowsePath = this._workspaceBrowseConfiguration.browsePath;
for (const includePathItem of normalizedIncludePath) {
if (newBrowsePath.indexOf(includePathItem) < 0) {
newBrowsePath.push(includePathItem);
}
}
if (sysroot) {
flags.push('--sysroot=' + sysroot);
}
this._workspaceBrowseConfiguration = {
browsePath: newBrowsePath,
standard,
compilerPath: normalizedCompilerPath || undefined,
compilerArgs: flags || undefined
};
this._workspaceBrowseConfigurations.set(util.platformNormalizePath(opts.folder), this._workspaceBrowseConfiguration);
return {
defines,
standard,
includePath: normalizedIncludePath,
intelliSenseMode: getIntelliSenseMode(this.cpptoolsVersion, comp_path, targetArchFromToolchains ?? targetArch),
compilerPath: normalizedCompilerPath || undefined,
compilerArgs: flags || undefined
};
}