From b7700ee678c56fc43bf343990d2609c34e5c287a Mon Sep 17 00:00:00 2001 From: David Amador Date: Sat, 29 Sep 2018 09:50:01 +0100 Subject: [PATCH 1/4] includeFiles in Visual Studio will now get ExcludedFromBuild tag too if they match conf.ResolvedSourceFilesBuildExclude --- .../VisualStudio/Vcxproj.Template.cs | 8 +++++ Sharpmake.Generators/VisualStudio/Vcxproj.cs | 32 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs index b6e6e762c..622324a52 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs @@ -222,6 +222,14 @@ public static class Project @" "; + public static string ProjectFilesHeaderBegin = + @" +"; + + public static string ProjectFilesHeaderEnd = + @" +"; + public static string ProjectFilesNatvis = @" "; diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index e1f8b54fd..18c581b44 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -1312,8 +1312,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); From 878042f239a4c2b2e4afdf0fcc1ab00c78fd68bf Mon Sep 17 00:00:00 2001 From: David Amador Date: Sat, 29 Sep 2018 11:08:47 +0100 Subject: [PATCH 2/4] Files are only added to a Visual Studio project if at least one of the project configurations doesn't exclude it --- Sharpmake.Generators/VisualStudio/Vcxproj.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index 18c581b44..d014602d1 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -1245,6 +1245,21 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera var customSourceFiles = new Dictionary>(); 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.ResolvedSourceFilesBuildExclude.Contains(projectFile.FileName) == false) + { + addFile = true; + break; + } + } + if (addFile == false) + { + continue; + } + string type = null; if (context.Project.ExtensionBuildTools.TryGetValue(projectFile.FileExtension, out type)) { From 8658b1342dd693b32fd09a7c7564fb113a130fbf Mon Sep 17 00:00:00 2001 From: David Amador Date: Wed, 3 Oct 2018 10:04:42 +0100 Subject: [PATCH 3/4] Fixed failure in regression_test.py, was missing updated samples "UpdateSamplesOutput.bat" in last commit --- .../qtfilecustombuild_vs2017_win64.vcxproj | 45 +++++-------------- ...lecustombuild_vs2017_win64.vcxproj.filters | 18 -------- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj index 909975cdc..149a398d0 100644 --- a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj +++ b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj @@ -373,9 +373,18 @@ - - - + + true + true + + + true + true + + + true + true + @@ -477,44 +486,14 @@ true true - - true - true - true - - - true - true - true - true true - - true - true - true - - - true - true - true - true true - - true - true - true - - - true - true - true - diff --git a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters index c875a4b0f..3f8cace2c 100644 --- a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters +++ b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters @@ -11,30 +11,12 @@ projects\obj\win64\qt\debug - - projects\obj\win64\qt\debug - - - projects\obj\win64\qt\debug - projects\obj\win64\qt\release - - projects\obj\win64\qt\release - - - projects\obj\win64\qt\release - projects\obj\win64\qt\retail - - projects\obj\win64\qt\retail - - - projects\obj\win64\qt\retail - From d0eedc322e41258351b31592a5dbae0422ba66f6 Mon Sep 17 00:00:00 2001 From: David Amador Date: Wed, 3 Oct 2018 20:34:05 +0100 Subject: [PATCH 4/4] Added SourceFilesExclude and Regex to Project.Configuration, it is now possible to use these properties to exclude files on a Configuration level Vcxprojec will now use ResolvedSourceFilesExclude instead of ResolveSourceFilesBuildExclude to determine if file should be added or not --- Sharpmake.Generators/VisualStudio/Vcxproj.cs | 2 +- Sharpmake/Project.Configuration.cs | 10 +++++++ Sharpmake/Project.cs | 16 ++++++++++ .../qtfilecustombuild_vs2017_win64.vcxproj | 30 +++++++++++++++++++ ...lecustombuild_vs2017_win64.vcxproj.filters | 18 +++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index d014602d1..b31d65cf2 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -1249,7 +1249,7 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera bool addFile = false; foreach (Project.Configuration conf in context.ProjectConfigurations) { - if (conf.ResolvedSourceFilesBuildExclude.Contains(projectFile.FileName) == false) + if (conf.ResolvedSourceFilesExclude.Contains(projectFile.FileName) == false) { addFile = true; break; diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs index f7baa5f98..132d8b43a 100644 --- a/Sharpmake/Project.Configuration.cs +++ b/Sharpmake/Project.Configuration.cs @@ -303,6 +303,14 @@ public OutputType Output public Strings SourceFilesFiltersRegex = new Strings(); + /// + /// Excluded file from project for this configuration + /// + public Strings SourceFilesExclude = new Strings(); + + public Strings SourceFilesExcludeRegex = new Strings(); + + /// /// Sources file that match this regex will be compiled as C Files /// @@ -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(); diff --git a/Sharpmake/Project.cs b/Sharpmake/Project.cs index f66a108fa..a0bfe8d9e 100644 --- a/Sharpmake/Project.cs +++ b/Sharpmake/Project.cs @@ -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(); @@ -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); } } diff --git a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj index 149a398d0..c47bb6b88 100644 --- a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj +++ b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj @@ -486,14 +486,44 @@ true true + + true + true + true + + + true + true + true + true true + + true + true + true + + + true + true + true + true true + + true + true + true + + + true + true + true + diff --git a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters index 3f8cace2c..c875a4b0f 100644 --- a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters +++ b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj.filters @@ -11,12 +11,30 @@ projects\obj\win64\qt\debug + + projects\obj\win64\qt\debug + + + projects\obj\win64\qt\debug + projects\obj\win64\qt\release + + projects\obj\win64\qt\release + + + projects\obj\win64\qt\release + projects\obj\win64\qt\retail + + projects\obj\win64\qt\retail + + + projects\obj\win64\qt\retail +