Skip to content

Commit 3f1b05b

Browse files
committed
Provide CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES as system includes
1 parent 2ef56fd commit 3f1b05b

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/cpptools.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,10 @@ export class CppConfigurationProvider implements cpptools.CustomConfigurationPro
468468

469469
const targetFromToolchains = compilerToolchains?.target;
470470
const targetArchFromToolchains = targetFromToolchains ? parseTargetArch(targetFromToolchains) : undefined;
471+
const compilerImplicitIncludes = compilerToolchains?.implicitIncludes?.map(util.platformNormalizePath) || [];
471472

472473
const normalizedCompilerPath = util.platformNormalizePath(compilerPath);
473-
let compileCommandFragments = useFragments ? (fileGroup.compileCommandFragments || target.compileCommandFragments) : [];
474+
const compileCommandFragments = useFragments ? (fileGroup.compileCommandFragments || target.compileCommandFragments).slice(0) : [];
474475
const getAsFlags = (fragments?: string[]) => {
475476
if (!fragments) {
476477
return [];
@@ -512,12 +513,33 @@ export class CppConfigurationProvider implements cpptools.CustomConfigurationPro
512513
}
513514
if (targetFromToolchains) {
514515
if (useFragments) {
515-
compileCommandFragments = compileCommandFragments.slice(0);
516516
compileCommandFragments.push(`--target=${targetFromToolchains}`);
517517
} else {
518518
flags.push(`--target=${targetFromToolchains}`);
519519
}
520520
}
521+
if (compilerImplicitIncludes.length > 0) {
522+
// Extract the stem from compiler path.
523+
const compilerId = compilerPath.toLocaleLowerCase()
524+
.match(/(?:^|[-\/\\])(cl|clang-cl|clang\+\+|clang|g\+\+|gcc)(?:$|[-.])/)?.[1] || "";
525+
526+
const includeFlag = {
527+
"cl": "/external:I",
528+
"clang-cl": "-imsvc",
529+
"clang++": "-isystem",
530+
"clang": "-isystem",
531+
"g++": "-isystem",
532+
"gcc": "-isystem"
533+
}[compilerId] || "-I";
534+
535+
for (const implicitInclude of compilerImplicitIncludes) {
536+
if (useFragments) {
537+
compileCommandFragments.push(`${includeFlag}${shlex.quote(implicitInclude)}`);
538+
} else {
539+
flags.push(`${includeFlag}${implicitInclude}`);
540+
}
541+
}
542+
}
521543

522544
this.workspaceBrowseConfiguration = {
523545
browsePath: newBrowsePath,

src/drivers/cmakeFileApi.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,7 @@ export async function loadToolchains(filename: string): Promise<Map<string, Code
594594

595595
return toolchains.toolchains.reduce((acc, el) => {
596596
if (el.compiler.path) {
597-
if (el.compiler.target) {
598-
acc.set(el.language, { path: el.compiler.path, target: el.compiler.target });
599-
} else {
600-
acc.set(el.language, { path: el.compiler.path });
601-
}
597+
acc.set(el.language, { path: el.compiler.path, implicitIncludes: el.compiler.implicit.includeDirectories });
602598
}
603599
return acc;
604600
}, new Map<string, CodeModelToolchain>());

src/drivers/codeModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type CodeModelFileGroup = api.CodeModel.FileGroup & { frameworks?: { path
1212
export type CodeModelProject = api.CodeModel.Project;
1313
// TODO: If requested, move folder, dependencies, and isGeneratorProvided definition to the public API repo to avoid this intersection type.
1414
export type CodeModelTarget = api.CodeModel.Target & { folder?: { name: string }; dependencies?: { backtrace: number; id: string }[]; isGeneratorProvided?: boolean; install?: {destinations: {path: string}[]; prefix: {path: string}}};
15-
export type CodeModelToolchain = api.CodeModel.Toolchain;
15+
export type CodeModelToolchain = api.CodeModel.Toolchain & { implicitIncludes?: string[] };
1616
export type TargetTypeString = api.CodeModel.TargetType;
1717

1818
/**

0 commit comments

Comments
 (0)