Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed system include paths handling in compilation database #354

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions Sharpmake.Generators/Generic/JsonCompilationDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private enum CompilerFlags
CreatePrecomp,
PrecompPath,
IncludePath,
IncludeSystemPath
}

private static readonly IDictionary<CompilerFlags, string> s_clangFlags = new Dictionary<CompilerFlags, string>
Expand All @@ -149,6 +150,7 @@ private enum CompilerFlags
{ CompilerFlags.UsePrecomp, "-include-pch {0}" },
{ CompilerFlags.CreatePrecomp, "-x c++-header {0}" },
{ CompilerFlags.IncludePath, "-I" },
{ CompilerFlags.IncludeSystemPath, "-isystem" },
};

private static readonly IDictionary<CompilerFlags, string> s_vcFlags = new Dictionary<CompilerFlags, string>
Expand All @@ -158,6 +160,7 @@ private enum CompilerFlags
{ CompilerFlags.CreatePrecomp, "/Yc\"{0}\" /FI\"{0}\"" },
{ CompilerFlags.PrecompPath, "/Fp\"{0}\"" },
{ CompilerFlags.IncludePath, "/I" },
{ CompilerFlags.IncludeSystemPath, "/external:I" },
};

private static readonly ProjectOptionsGenerator s_optionGenerator = new ProjectOptionsGenerator();
Expand Down Expand Up @@ -274,13 +277,18 @@ private void FillIncludeDirectoriesOptions(CompileCommandGenerationContext conte
var platformDescriptor = PlatformRegistry.Get<IPlatformDescriptor>(context.Configuration.Platform);

string defaultCmdLineIncludePrefix = _flags[CompilerFlags.IncludePath];
string defaultCmdLineIncludeSystemPrefix = _flags[CompilerFlags.IncludeSystemPath];

// Fill include dirs
var dirs = new List<string>();

var platformIncludePaths = platformVcxproj.GetPlatformIncludePathsWithPrefix(context);
var platformIncludePathsPrefixed = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, p.Path, p.CmdLinePrefix)).ToList();
var platformIncludePaths = context.Configuration.IncludePaths;
var platformIncludeSystemPaths = context.Configuration.IncludeSystemPaths;
var platformIncludePathsPrefixed = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, p, defaultCmdLineIncludePrefix)).ToList();
var platformIncludeSystemPathsPrefixed = platformIncludeSystemPaths.Select(p => CmdLineConvertIncludePathsFunc(context, p, defaultCmdLineIncludeSystemPrefix)).ToList();

dirs.AddRange(platformIncludePathsPrefixed);
dirs.AddRange(platformIncludeSystemPathsPrefixed);

// TODO: move back up, just below the creation of the dirs list
dirs.AddRange(includePaths.Select(p => CmdLineConvertIncludePathsFunc(context, p, defaultCmdLineIncludePrefix)));
Expand All @@ -300,7 +308,7 @@ private void FillIncludeDirectoriesOptions(CompileCommandGenerationContext conte
{
// with LLVM as toolchain, we are still using the default resource compiler, so we need the default include prefix
// TODO: this is not great, ideally we would need the prefix to be per "compiler", and a platform can have many
var platformIncludePathsDefaultPrefix = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, p.Path, defaultCmdLineIncludePrefix));
var platformIncludePathsDefaultPrefix = platformIncludePaths.Select(p => CmdLineConvertIncludePathsFunc(context, p, defaultCmdLineIncludePrefix));
resourceDirs.AddRange(platformIncludePathsDefaultPrefix);
}
else
Expand Down
Loading