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

[Visual Studio] header files with exclude tag and remove from project if all configurations ignore it #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ public static class Project
@" <ClInclude Include=""[file.FileNameProjectRelative]"" />
";

public static string ProjectFilesHeaderBegin =
@" <ClInclude Include=""[file.FileNameProjectRelative]"" >
";

public static string ProjectFilesHeaderEnd =
@" </ClInclude>
";

public static string ProjectFilesNatvis =
@" <Natvis Include=""[file.FileNameProjectRelative]"" />
";
Expand Down
47 changes: 46 additions & 1 deletion Sharpmake.Generators/VisualStudio/Vcxproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,21 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera
var customSourceFiles = new Dictionary<string, List<ProjectFile>>();
foreach (ProjectFile projectFile in allFiles)
{
//First check if this projectFile is present in any of the configuration, if excluded from all, don't add it
bool addFile = false;
foreach (Project.Configuration conf in context.ProjectConfigurations)
{
if (conf.ResolvedSourceFilesExclude.Contains(projectFile.FileName) == false)
{
addFile = true;
break;
}
}
if (addFile == false)
{
continue;
}

string type = null;
if (context.Project.ExtensionBuildTools.TryGetValue(projectFile.FileExtension, out type))
{
Expand Down Expand Up @@ -1312,8 +1327,38 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera
{
foreach (ProjectFile file in includeFiles)
{
bool writeEnd = false;
using (fileGenerator.Declare("file", file))
fileGenerator.Write(Template.Project.ProjectFilesHeader);
{
foreach (Project.Configuration conf in context.ProjectConfigurations)
{
using (fileGenerator.Declare("conf", conf))
using (fileGenerator.Declare("platformName", Util.GetPlatformString(conf.Platform, conf.Project)))
{
bool isExcludeFromBuild = conf.ResolvedSourceFilesBuildExclude.Contains(file.FileName);
if (isExcludeFromBuild)
{
if (writeEnd == false)
{
fileGenerator.Write(Template.Project.ProjectFilesHeaderBegin);
writeEnd = true;
}
fileGenerator.Write(Template.Project.ProjectFilesSourceExcludeFromBuild);
}

}
}

if (writeEnd)
{
fileGenerator.Write(Template.Project.ProjectFilesHeaderEnd);
}
else
{
fileGenerator.Write(Template.Project.ProjectFilesHeader);
}
}

}
}
fileGenerator.Write(Template.Project.ProjectFilesEnd);
Expand Down
10 changes: 10 additions & 0 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ public OutputType Output

public Strings SourceFilesFiltersRegex = new Strings();

/// <summary>
/// Excluded file from project for this configuration
/// </summary>
public Strings SourceFilesExclude = new Strings();

public Strings SourceFilesExcludeRegex = new Strings();


/// <summary>
/// Sources file that match this regex will be compiled as C Files
/// </summary>
Expand Down Expand Up @@ -1045,6 +1053,8 @@ public void GeneratorSetGeneratedInformation(string executableExtension, string

public Strings ResolvedSourceFilesBuildExclude = new Strings();

public Strings ResolvedSourceFilesExclude = new Strings();

public Strings ResolvedSourceFilesBlobExclude = new Strings();

public Strings ResolvedSourceFilesWithCompileAsCOption = new Strings();
Expand Down
16 changes: 16 additions & 0 deletions Sharpmake/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,23 @@ internal virtual void ResolveSourceFiles(Builder builder)
if (conf.IsFastBuild && conf.FastBuildBlobbed)
fastBuildBlobs = true;

var confSourceFilesExcludeRegex = RegexCache.GetCachedRegexes(conf.SourceFilesExcludeRegex);

// Remove file that match conf.SourceFilesExcludeRegex
if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, SourceFiles), SourceFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
System.Diagnostics.Debugger.Break();
if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, ResourceFiles), ResourceFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
System.Diagnostics.Debugger.Break();
if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, NatvisFiles), NatvisFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
System.Diagnostics.Debugger.Break();

conf.ResolvedSourceFilesBuildExclude.AddRange(SourceFilesExclude);

//Add SourceFilesExclude also to ResolvedSourceFilesBuildExclude in case we end up needing file for
//another configuration that way it gets added but excluded from build in this config
conf.ResolvedSourceFilesBuildExclude.AddRange(conf.SourceFilesExclude);
conf.ResolvedSourceFilesExclude.AddRange(conf.SourceFilesExclude);

// add SourceFilesBuildExclude from the project
if (DebugBreaks.ShouldBreakOnSourcePath(DebugBreaks.Context.Resolving, ResolvedSourceFilesBuildExclude))
System.Diagnostics.Debugger.Break();
Expand Down Expand Up @@ -939,6 +954,7 @@ internal virtual void ResolveSourceFiles(Builder builder)
conf.ResolvedSourceFilesBuildExclude.Add(sourceFile);
}
Util.ResolvePath(SourceRootPath, ref conf.ResolvedSourceFilesBuildExclude);
Util.ResolvePath(SourceRootPath, ref conf.ResolvedSourceFilesExclude);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,18 @@
<ItemGroup>
<ClInclude Include="..\codebase\stdafx.h" />
<ClInclude Include="obj\qtfilecustombuild\qt\ui_privatewidget.h" />
<ClInclude Include="obj\win64\qt\debug\privatewidget.moc" />
<ClInclude Include="obj\win64\qt\release\privatewidget.moc" />
<ClInclude Include="obj\win64\qt\retail\privatewidget.moc" />
<ClInclude Include="obj\win64\qt\debug\privatewidget.moc" >
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Retail|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="obj\win64\qt\release\privatewidget.moc" >
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Retail|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="obj\win64\qt\retail\privatewidget.moc" >
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\codebase\exec.qrc">
Expand Down