diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f9afa233..488abdd757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Improvements: - Improve CMake syntax highlighting with command-scoped keyword rules, expanded variable recognition, and better generator-expression support. Remove obsolete deprecated-keyword entries that caused false positives on user-defined names. [#4709](https://github.com/microsoft/vscode-cmake-tools/issues/4709) [#4508](https://github.com/microsoft/vscode-cmake-tools/issues/4508) [#4613](https://github.com/microsoft/vscode-cmake-tools/issues/4613) - Add MSVC linker error problem matching to the Problems pane. [#4675](https://github.com/microsoft/vscode-cmake-tools/pull/4675) [@bradphelan](https://github.com/bradphelan) - Use environment variables from `cmake.environment` and `cmake.configureEnvironment` when expanding `$penv{}` macros in CMake Presets `include` paths. [#3578](https://github.com/microsoft/vscode-cmake-tools/issues/3578) +- Provide CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES as system includes. [#4718](https://github.com/microsoft/vscode-cmake-tools/pull/4718) - Allow preset modification commands to target CMakeUserPresets.json. The target file is determined by the focused editor, or by prompting the user when both files exist. [#4564](https://github.com/microsoft/vscode-cmake-tools/issues/4564) Bug Fixes: diff --git a/src/cpptools.ts b/src/cpptools.ts index 79e0752335..abc0819367 100644 --- a/src/cpptools.ts +++ b/src/cpptools.ts @@ -468,9 +468,10 @@ export class CppConfigurationProvider implements cpptools.CustomConfigurationPro const targetFromToolchains = compilerToolchains?.target; const targetArchFromToolchains = targetFromToolchains ? parseTargetArch(targetFromToolchains) : undefined; + const compilerImplicitIncludes = compilerToolchains?.implicitIncludes?.map(util.platformNormalizePath) || []; const normalizedCompilerPath = util.platformNormalizePath(compilerPath); - let compileCommandFragments = useFragments ? (fileGroup.compileCommandFragments || target.compileCommandFragments) : []; + const compileCommandFragments = useFragments ? (fileGroup.compileCommandFragments || target.compileCommandFragments).slice(0) : []; const getAsFlags = (fragments?: string[]) => { if (!fragments) { return []; @@ -512,12 +513,33 @@ export class CppConfigurationProvider implements cpptools.CustomConfigurationPro } if (targetFromToolchains) { if (useFragments) { - compileCommandFragments = compileCommandFragments.slice(0); compileCommandFragments.push(`--target=${targetFromToolchains}`); } else { flags.push(`--target=${targetFromToolchains}`); } } + if (compilerImplicitIncludes.length > 0) { + // Extract the stem from compiler path. + const compilerId = compilerPath.toLocaleLowerCase() + .match(/(?:^|[-\/\\])(cl|clang-cl|clang\+\+|clang|g\+\+|gcc)(?:$|[-.])/)?.[1] || ""; + + const includeFlag = { + "cl": "/external:I", + "clang-cl": "-imsvc", + "clang++": "-isystem", + "clang": "-isystem", + "g++": "-isystem", + "gcc": "-isystem" + }[compilerId] || "-I"; + + for (const implicitInclude of compilerImplicitIncludes) { + if (useFragments) { + compileCommandFragments.push(`${includeFlag}${shlex.quote(implicitInclude)}`); + } else { + flags.push(`${includeFlag}${implicitInclude}`); + } + } + } this.workspaceBrowseConfiguration = { browsePath: newBrowsePath, diff --git a/src/drivers/cmakeFileApi.ts b/src/drivers/cmakeFileApi.ts index eafea56e54..86625cf3d0 100644 --- a/src/drivers/cmakeFileApi.ts +++ b/src/drivers/cmakeFileApi.ts @@ -594,11 +594,11 @@ export async function loadToolchains(filename: string): Promise { if (el.compiler.path) { - if (el.compiler.target) { - acc.set(el.language, { path: el.compiler.path, target: el.compiler.target }); - } else { - acc.set(el.language, { path: el.compiler.path }); - } + acc.set(el.language, { + path: el.compiler.path, + target: el.compiler.target, + implicitIncludes: el.compiler.implicit.includeDirectories + }); } return acc; }, new Map()); diff --git a/src/drivers/codeModel.ts b/src/drivers/codeModel.ts index 09a395d209..1caa7a1fb5 100644 --- a/src/drivers/codeModel.ts +++ b/src/drivers/codeModel.ts @@ -12,7 +12,7 @@ export type CodeModelFileGroup = api.CodeModel.FileGroup & { frameworks?: { path export type CodeModelProject = api.CodeModel.Project; // TODO: If requested, move folder, dependencies, and isGeneratorProvided definition to the public API repo to avoid this intersection type. export type CodeModelTarget = api.CodeModel.Target & { folder?: { name: string }; dependencies?: { backtrace: number; id: string }[]; isGeneratorProvided?: boolean; install?: {destinations: {path: string}[]; prefix: {path: string}}}; -export type CodeModelToolchain = api.CodeModel.Toolchain; +export type CodeModelToolchain = api.CodeModel.Toolchain & { implicitIncludes?: string[] }; export type TargetTypeString = api.CodeModel.TargetType; /**