From 41966c712db87b252d83593c391951453cc45987 Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Thu, 15 Mar 2018 15:02:31 +0100 Subject: Disable dynamic C++ source if already included When converting from custom build to Qt/MSBuild, if a moc header does not have a corresponding generated file, disable the dynamic C++ source for that moc header. This is needed for the case when the moc output is #include'd in the associated source file instead of being compiled on its own. Task-number: QTVSADDINBUG-530 Change-Id: Iae136ff6a14c867ed3250aa255b0681b77bcc29e Reviewed-by: Joerg Bornemann --- src/qtprojectlib/MsBuildProject.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/qtprojectlib/MsBuildProject.cs') diff --git a/src/qtprojectlib/MsBuildProject.cs b/src/qtprojectlib/MsBuildProject.cs index 76faae2a..aca3f4a8 100644 --- a/src/qtprojectlib/MsBuildProject.cs +++ b/src/qtprojectlib/MsBuildProject.cs @@ -374,7 +374,7 @@ namespace QtProjectLib return ouputFile; } - void RemoveGeneratedFiles( + bool RemoveGeneratedFiles( List cbEvals, string configName, string itemName, @@ -382,6 +382,7 @@ namespace QtProjectLib IEnumerable filterItems) { //remove items with generated files + bool hasGeneratedFiles = false; var cbEval = cbEvals .Where(x => x.ProjectConfig == configName && x.Identity == itemName) .FirstOrDefault(); @@ -396,11 +397,13 @@ namespace QtProjectLib outputItems.AddRange(filterItems .Where(x => HelperFunctions.PathEquals( outputFile, (string)x.Attribute("Include")))); + hasGeneratedFiles |= outputItems.Any(); foreach (var item in outputItems) item.Remove(); } } } + return hasGeneratedFiles; } public bool ConvertCustomBuildToQtMsBuild() @@ -508,12 +511,14 @@ namespace QtProjectLib Path.GetDirectoryName(this[Files.Project].filePath))) { return false; } + List mocDisableDynamicSource = new List(); foreach (var qtMoc in mocCustomBuilds.Elements(ns + QtMoc.ItemTypeName)) { var itemName = (string)qtMoc.Attribute("Include"); var configName = (string)qtMoc.Attribute("ConfigName"); //remove items with generated files - RemoveGeneratedFiles(cbEvals, configName, itemName, projectItems, filterItems); + var hasGeneratedFiles = RemoveGeneratedFiles( + cbEvals, configName, itemName, projectItems, filterItems); //set properties qtMsBuild.SetItemProperty(qtMoc, @@ -526,6 +531,8 @@ namespace QtProjectLib QtVSIPSettings.GetMocDirectory())); qtMsBuild.SetItemProperty(qtMoc, QtMoc.Property.DynamicSource, "output"); + if (!hasGeneratedFiles) + mocDisableDynamicSource.Add(qtMoc); } else { qtMsBuild.SetItemProperty(qtMoc, QtMoc.Property.OutputFile, string.Format(@"{0}\%(Filename).moc", @@ -589,6 +596,13 @@ namespace QtProjectLib qtMsBuild.EndSetItemProperties(); + //disable dynamic C++ source for moc headers without generated files + //(needed for the case of #include "moc_foo.cpp" in source file) + foreach (var qtMoc in mocDisableDynamicSource) { + qtMsBuild.SetItemProperty(qtMoc, + QtMoc.Property.DynamicSource, "false"); + } + FinalizeProjectChanges(mocCustomBuilds.ToList(), QtMoc.ItemTypeName); FinalizeProjectChanges(rccCustomBuilds.ToList(), QtRcc.ItemTypeName); FinalizeProjectChanges(uicCustomBuilds.ToList(), QtUic.ItemTypeName); -- cgit v1.2.3