From cff73364c3b632a84ab3c7ca2f2ea32b563910ce Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Mon, 8 Jul 2019 16:16:15 +0200 Subject: Add C++ compiler properties to Qt tools Qt tools that generate C++ code will now include all properties available in the C++ compiler property page, allowing the default values of the C++ compiler properties to be used directly by the Qt tools, without the need to actively monitor changes to maintain properties synchronized. It is also possible to extend (i.e. append to) or override (i.e. replace) the default C++ property values for Qt tools. Task-number: QTVSADDINBUG-575 Task-number: QTVSADDINBUG-632 Change-Id: I456ee6b4926cd11c83c845656a617a4fb204542a Reviewed-by: Oliver Wolff --- .gitignore | 6 ++ src/common.tt | 45 ++++++++++ src/qtmsbuild/moc/qtmoc.targets | 12 +++ src/qtmsbuild/moc/qtmoc_cl.targets_TT | 143 ++++++++++++++++++++++++++++++++ src/qtmsbuild/moc/qtmoc_cl.xml_TT | 112 +++++++++++++++++++++++++ src/qtmsbuild/qt.props | 8 ++ src/qtmsbuild/qt.targets | 3 + src/qtmsbuild/qt_globals.targets | 5 ++ src/qtmsbuild/rcc/qtrcc.targets | 12 +++ src/qtmsbuild/rcc/qtrcc_cl.targets_TT | 103 +++++++++++++++++++++++ src/qtmsbuild/rcc/qtrcc_cl.xml_TT | 109 ++++++++++++++++++++++++ src/qtmsbuild/repc/qtrepc.targets | 12 +++ src/qtmsbuild/repc/qtrepc_cl.targets_TT | 121 +++++++++++++++++++++++++++ src/qtmsbuild/repc/qtrepc_cl.xml_TT | 112 +++++++++++++++++++++++++ src/qtprojectlib/ProjectExporter.cs | 6 ++ src/qtprojectlib/QtProject.cs | 7 ++ src/qtprojectlib/Resources.cs | 3 + src/qtvstools/DteEventsHandler.cs | 6 ++ src/qtvstools/QtVsTools.csproj | 99 ++++++++++++++++++++++ 19 files changed, 924 insertions(+) create mode 100644 src/qtmsbuild/moc/qtmoc_cl.targets_TT create mode 100644 src/qtmsbuild/moc/qtmoc_cl.xml_TT create mode 100644 src/qtmsbuild/rcc/qtrcc_cl.targets_TT create mode 100644 src/qtmsbuild/rcc/qtrcc_cl.xml_TT create mode 100644 src/qtmsbuild/repc/qtrepc_cl.targets_TT create mode 100644 src/qtmsbuild/repc/qtrepc_cl.xml_TT diff --git a/.gitignore b/.gitignore index 824abebe..7fcb86e4 100644 --- a/.gitignore +++ b/.gitignore @@ -297,3 +297,9 @@ src/qttemplates/server/server.vstemplate src/qtvstools/QtMenus.vsct MSBuild.MetaInfo.cs src/qtvstools/Marketplace/Overview.html +src/qtmsbuild/moc/qtmoc_cl.xml +src/qtmsbuild/moc/qtmoc_cl.targets +src/qtmsbuild/rcc/qtrcc_cl.xml +src/qtmsbuild/rcc/qtrcc_cl.targets +src/qtmsbuild/repc/qtrepc_cl.xml +src/qtmsbuild/repc/qtrepc_cl.targets diff --git a/src/common.tt b/src/common.tt index bc5342e8..d8edd875 100644 --- a/src/common.tt +++ b/src/common.tt @@ -1,7 +1,14 @@ <#@template hostspecific="true" language="C#" #> <#@assembly Name="System.Core" #> +<#@assembly Name="System.Xml" #> +<#@assembly Name="System.Xml.Linq" #> <#@import namespace="System" #> +<#@import namespace="System.Collections.Generic" #> <#@import namespace="System.IO" #> +<#@import namespace="System.Linq" #> +<#@import namespace="System.Text" #> +<#@import namespace="System.Xml" #> +<#@import namespace="System.Xml.Linq" #> <#@assembly name="EnvDTE" #> <#@import namespace="EnvDTE" #> <# @@ -39,8 +46,46 @@ VS_VERSION.StartsWith("15.") ? "2017" : VS_VERSION.StartsWith("14.") ? "2015" : VS_VERSION.StartsWith("12.") ? "2013" : "????"; + string VS_EDITION = Dte.Edition; + string VC_TARGETS_PATH = Path.Combine( + Environment.GetEnvironmentVariable("ProgramFiles(x86)"), + VS_VERSION.StartsWith("16.") ? + @"Microsoft Visual Studio\2019\" + VS_EDITION + @"\MSBuild\Microsoft\VC\v160" : + VS_VERSION.StartsWith("15.") ? + @"Microsoft Visual Studio\2017\" + VS_EDITION + @"\Common7\IDE\VC\VCTargets" : + VS_VERSION.StartsWith("14.") ? + @"MSBuild\Microsoft.Cpp\v4.0\V140" : + VS_VERSION.StartsWith("12.") ? + @"MSBuild\Microsoft.Cpp\v4.0\V120" : null); /***************************************************************************/ string WARNING_GENERATED_FILE = "This file was generated automatically."; string XML_COMMENT_BEGIN = ""; + + var XmlLoad = new Func(xmlText => + { + XDocument xmlDoc = null; + using (var reader = XmlReader.Create(new StringReader(xmlText))) + xmlDoc = XDocument.Load(reader); + var xmlRoot = xmlDoc.Root; + xmlRoot.Descendants().ToList().ForEach(x => x.Name = x.Name.LocalName); + return xmlRoot; + }); + + var XmlPrint = new Func, string>(x => + { + var xmlOut = new StringBuilder(); + var xmlOutSettings = new XmlWriterSettings() + { + ConformanceLevel = ConformanceLevel.Fragment, + OmitXmlDeclaration = true, + Indent = true, + }; + using (var xmlOutWriter = XmlWriter.Create(xmlOut, xmlOutSettings)) { + foreach (var y in x) + y.WriteTo(xmlOutWriter); + } + return xmlOut.ToString(); + }); + #> \ No newline at end of file diff --git a/src/qtmsbuild/moc/qtmoc.targets b/src/qtmsbuild/moc/qtmoc.targets index acbdc89a..276a16ae 100644 --- a/src/qtmsbuild/moc/qtmoc.targets +++ b/src/qtmsbuild/moc/qtmoc.targets @@ -61,6 +61,9 @@ + Qt;_ClCompile @@ -152,6 +155,14 @@ + + + + + + + + + + %(QtMoc.OverrideClCompile) + + + + + + + + %(QtMoc.AdditionalIncludeDirectories) + %(QtMoc.PreprocessorDefinitions) + %(QtMoc.UndefinePreprocessorDefinitions) + + + + + + %(QtMoc.AdditionalIncludeDirectories) + @(ClCompile-> + WithMetadataValue('Identity', 'DefaultClCompile')-> + '%(AdditionalIncludeDirectories)') + %(QtMoc.PreprocessorDefinitions) + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(PreprocessorDefinitions)') + %(QtMoc.UndefinePreprocessorDefinitions) + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(UndefinePreprocessorDefinitions)') + + + + + + + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(AdditionalIncludeDirectories)') + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(PreprocessorDefinitions)') + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(UndefinePreprocessorDefinitions)') + + + + + + + + + diff --git a/src/qtmsbuild/moc/qtmoc_cl.xml_TT b/src/qtmsbuild/moc/qtmoc_cl.xml_TT new file mode 100644 index 00000000..77c3c116 --- /dev/null +++ b/src/qtmsbuild/moc/qtmoc_cl.xml_TT @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtmsbuild/qt.props b/src/qtmsbuild/qt.props index 9a948da4..4f7fa0d5 100644 --- a/src/qtmsbuild/qt.props +++ b/src/qtmsbuild/qt.props @@ -42,6 +42,7 @@ 0 300 + 300 @@ -53,6 +54,13 @@ >true false + + true + false + + + + + + + + + %(QtRcc.OverrideClCompile) + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtmsbuild/rcc/qtrcc_cl.xml_TT b/src/qtmsbuild/rcc/qtrcc_cl.xml_TT new file mode 100644 index 00000000..63da25a6 --- /dev/null +++ b/src/qtmsbuild/rcc/qtrcc_cl.xml_TT @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/qtmsbuild/repc/qtrepc.targets b/src/qtmsbuild/repc/qtrepc.targets index 94418476..4cf63a73 100644 --- a/src/qtmsbuild/repc/qtrepc.targets +++ b/src/qtmsbuild/repc/qtrepc.targets @@ -58,6 +58,9 @@ + Qt @@ -145,6 +148,14 @@ + + + + + + + + + + %(QtRepc.OverrideClCompile) + + + + + + + + %(QtRepc.AdditionalIncludeDirectories) + + + + + + %(QtRepc.AdditionalIncludeDirectories) + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(AdditionalIncludeDirectories)') + + + + + + + @(ClCompile-> + WithMetadataValue('Identity','DefaultClCompile')-> + '%(AdditionalIncludeDirectories)') + + + + + + + + + diff --git a/src/qtmsbuild/repc/qtrepc_cl.xml_TT b/src/qtmsbuild/repc/qtrepc_cl.xml_TT new file mode 100644 index 00000000..563c7bda --- /dev/null +++ b/src/qtmsbuild/repc/qtrepc_cl.xml_TT @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtprojectlib/ProjectExporter.cs b/src/qtprojectlib/ProjectExporter.cs index e70b6060..a1cbd7be 100644 --- a/src/qtprojectlib/ProjectExporter.cs +++ b/src/qtprojectlib/ProjectExporter.cs @@ -417,6 +417,9 @@ namespace QtProjectLib private static void AddIncludePaths(Project project, ProFileOption option, string includePaths) { + if (QtProject.GetFormatVersion(project) >= Resources.qtMinFormatVersion_ClProperties) + return; + if (includePaths == null) return; @@ -449,6 +452,9 @@ namespace QtProjectLib private static void AddLibraries(Project project, ProFileOption option, string paths, string deps) { + if (QtProject.GetFormatVersion(project) < Resources.qtMinFormatVersion_ClProperties) + return; + var versionManager = QtVersionManager.The(); var qtDir = versionManager.GetInstallPath(project); if (qtDir == null) diff --git a/src/qtprojectlib/QtProject.cs b/src/qtprojectlib/QtProject.cs index 15067709..09aef94d 100644 --- a/src/qtprojectlib/QtProject.cs +++ b/src/qtprojectlib/QtProject.cs @@ -2312,6 +2312,9 @@ namespace QtProjectLib public void AddActiveQtBuildStep(string version, string defFile = null) { + if (FormatVersion < Resources.qtMinFormatVersion_ClProperties) + return; + foreach (VCConfiguration config in (IVCCollection) vcPro.Configurations) { var idlFile = "\"$(IntDir)/" + envPro.Name + ".idl\""; var tblFile = "\"$(IntDir)/" + envPro.Name + ".tlb\""; @@ -2637,6 +2640,10 @@ namespace QtProjectLib public void RefreshMocSteps() { + // Ignore when using shared compiler properties + if (GetFormatVersion(vcPro) >= Resources.qtMinFormatVersion_ClProperties) + return; + var filesCollection = vcPro.Files as IVCCollection; if (filesCollection == null) return; diff --git a/src/qtprojectlib/Resources.cs b/src/qtprojectlib/Resources.cs index 65ad451f..68b36028 100644 --- a/src/qtprojectlib/Resources.cs +++ b/src/qtprojectlib/Resources.cs @@ -88,6 +88,9 @@ namespace QtProjectLib // Min. format version for Qt settings as project properties public const int qtMinFormatVersion_Settings = 300; + // Min. format version for shared compiler properties + public const int qtMinFormatVersion_ClProperties = 300; + // Project properties labels public const string projLabelGlobals = "Globals"; public const string projLabelConfiguration = "Configuration"; diff --git a/src/qtvstools/DteEventsHandler.cs b/src/qtvstools/DteEventsHandler.cs index 03c6da89..516bc585 100644 --- a/src/qtvstools/DteEventsHandler.cs +++ b/src/qtvstools/DteEventsHandler.cs @@ -598,6 +598,9 @@ namespace QtVsTools return; if (!HelperFunctions.IsQtProject(vcPrj)) return; + // Ignore property events when using shared compiler properties + if (QtProject.GetFormatVersion(vcPrj) >= Resources.qtMinFormatVersion_ClProperties) + return; if (dispid == dispId_VCCLCompilerTool_UsePrecompiledHeader || dispid == dispId_VCCLCompilerTool_PrecompiledHeaderThrough @@ -627,6 +630,9 @@ namespace QtVsTools return; if (!HelperFunctions.IsQtProject(vcPrj)) return; + // Ignore property events when using shared compiler properties + if (QtProject.GetFormatVersion(vcPrj) >= Resources.qtMinFormatVersion_ClProperties) + return; if (dispid == dispId_VCFileConfiguration_ExcludedFromBuild) { var qtPrj = QtProject.Create(vcPrj); diff --git a/src/qtvstools/QtVsTools.csproj b/src/qtvstools/QtVsTools.csproj index 54ab5cd1..d75c8d43 100644 --- a/src/qtvstools/QtVsTools.csproj +++ b/src/qtvstools/QtVsTools.csproj @@ -598,6 +598,39 @@ true Designer + + QtMsBuild\moc\qtmoc_cl.xml_TT + TextTemplatingFileGenerator + ..\qtmsbuild\moc\qtmoc_cl.xml + $(SolutionDir)\version.targets;$(SolutionDir)\version.tt;$(SolutionDir)\common.tt + qtmoc_cl.xml + Designer + + + QtMsBuild\moc\qtmoc_cl.xml + True + True + qtmoc_cl.xml_TT + Designer + Always + true + + + QtMsBuild\moc\qtmoc_cl.targets_TT + TextTemplatingFileGenerator + ..\qtmsbuild\moc\qtmoc_cl.targets + $(SolutionDir)\version.targets;$(SolutionDir)\version.tt;$(SolutionDir)\common.tt + Designer + qtmoc_cl.targets + + + QtMsBuild\moc\qtmoc_cl.targets + True + True + qtmoc_cl.targets_TT + Always + true +