From d22f0aa651ad794fea6ec036a67ed2e112f41bdf Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Thu, 16 Nov 2017 10:41:04 +0100 Subject: Add MSBuild targets for Qt Added MSBuild customization files to support Qt-specific tasks like moc, rcc, uic. Instead of custom build steps that only allow a command line field, which has to be specified for each project item, MSBuild targets allow each tool to have a dedicated dialog (or "property page") with one field per tool option. Common options can be specified only once at project/configuration level and inherited by all items of the same type. Unlike custom build steps that can only run in sequence, using the Qt MSBuild targets it is possible to run the tools in parallel processes. Change-Id: Ie348bccec0402c10299096e51381a88e4a58dad2 Reviewed-by: Oliver Wolff --- src/config/12.0/source.extension.vsixmanifest | 5 + src/config/14.0/source.extension.vsixmanifest | 5 + src/config/15.0/source.extension.vsixmanifest | 5 + src/qtmsbuild/qt.props | 71 +++++ src/qtmsbuild/qt.targets | 415 ++++++++++++++++++++++++++ src/qtmsbuild/qtmoc.xml | 244 +++++++++++++++ src/qtmsbuild/qtrcc.xml | 270 +++++++++++++++++ src/qtmsbuild/qtuic.xml | 190 ++++++++++++ src/qttemplates/console/console.vcxproj | 15 + src/qttemplates/designer/designer.vcxproj | 15 + src/qttemplates/gui/gui.vcxproj | 15 + src/qttemplates/lib/lib.vcxproj | 15 + src/qttemplates/server/server.vcxproj | 15 + src/qtvstools/QtVsTools.csproj | 25 ++ src/qtvstools/Vsix.cs | 11 + 15 files changed, 1316 insertions(+) create mode 100644 src/qtmsbuild/qt.props create mode 100644 src/qtmsbuild/qt.targets create mode 100644 src/qtmsbuild/qtmoc.xml create mode 100644 src/qtmsbuild/qtrcc.xml create mode 100644 src/qtmsbuild/qtuic.xml diff --git a/src/config/12.0/source.extension.vsixmanifest b/src/config/12.0/source.extension.vsixmanifest index 739bc19f..39afee71 100644 --- a/src/config/12.0/source.extension.vsixmanifest +++ b/src/config/12.0/source.extension.vsixmanifest @@ -77,5 +77,10 @@ d:Source="File" Path="x86\SQLite.Interop.dll" d:VsixSubPath="x86" /> + + + + + diff --git a/src/config/14.0/source.extension.vsixmanifest b/src/config/14.0/source.extension.vsixmanifest index 7b5f743f..4e9b2056 100644 --- a/src/config/14.0/source.extension.vsixmanifest +++ b/src/config/14.0/source.extension.vsixmanifest @@ -77,5 +77,10 @@ d:Source="File" Path="x86\SQLite.Interop.dll" d:VsixSubPath="x86" /> + + + + + diff --git a/src/config/15.0/source.extension.vsixmanifest b/src/config/15.0/source.extension.vsixmanifest index b37c28f4..b2978032 100644 --- a/src/config/15.0/source.extension.vsixmanifest +++ b/src/config/15.0/source.extension.vsixmanifest @@ -77,6 +77,11 @@ d:Source="File" Path="x86\SQLite.Interop.dll" d:VsixSubPath="x86" /> + + + + + + + + ClCompile + CustomBuild + + + + _SelectedFiles;$(QtMocDependsOn) + + + + + Moc%27ing %(Identity)... + $(QTDIR) + %(FullPath) + $(ProjectDir)GeneratedFiles\$(Configuration)\moc_%(Filename).cpp + true + [AllOptions] [AdditionalOptions] + %(OutputFile) + + + + ClCompile + CustomBuild + + + + _SelectedFiles;$(QtRccDependsOn) + + + + + Rcc%27ing %(Identity)... + $(QTDIR) + %(FullPath) + $(ProjectDir)GeneratedFiles\qrc_%(Filename).cpp + %(Filename) + default + true + [AllOptions] [AdditionalOptions] + %(OutputFile) + + + + ClCompile + CustomBuild + + + + _SelectedFiles;$(QtUicDependsOn) + + + + + Uic%27ing %(Identity)... + $(QTDIR) + %(FullPath) + $(ProjectDir)GeneratedFiles\ui_%(Filename).h + true + [AllOptions] [AdditionalOptions] + %(OutputFile) + + + diff --git a/src/qtmsbuild/qt.targets b/src/qtmsbuild/qt.targets new file mode 100644 index 00000000..ec12d249 --- /dev/null +++ b/src/qtmsbuild/qt.targets @@ -0,0 +1,415 @@ + + + + + false + + + $(ProjectDir)$(IntDir)qt.txt + + + $([System.Environment]::ProcessorCount) + + + + + + + + + + + + QtMoc + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName)moc.xml + + + + + + + + + @(QtMoc, '|') + + + + + + + + + + + + + + + + + + QtRcc + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName)rcc.xml + + + + + + + + + @(QtRcc, '|') + + + + + + + + + + + + + + + + + + QtUic + + + + $(MSBuildThisFileDirectory)$(MSBuildThisFileName)uic.xml + + + + + + + + + @(QtUic, '|') + + + + + + + + + + + + + + + + + + + + + + + + + + + childRunningProcs = new Queue(); + bool ok = true; + foreach (var qtCmdLin in File.ReadLines(WorkFilePath)) { + + if (!ok) + break; + + string[] qtCmdCol = qtCmdLin.Split(new char[] { ';' }); + if (qtCmdCol.Length < 3) { + ok = false; + break; + } + + Log.LogMessage(MessageImportance.High, qtCmdCol[0]); + + var procInfo = new ProcessStartInfo + { + FileName = qtCmdCol[1], + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true, + Arguments = qtCmdCol[2] + }; + try { + var childProcess = Process.Start(procInfo); + childProcess.OutputDataReceived += + (object sender, DataReceivedEventArgs e) => { + if (!string.IsNullOrEmpty(e.Data)) + Log.LogMessage(MessageImportance.High, e.Data); + }; + childProcess.ErrorDataReceived += + (object sender, DataReceivedEventArgs e) => { + if (!string.IsNullOrEmpty(e.Data)) + Log.LogMessage(MessageImportance.High, e.Data); + }; + childProcess.BeginOutputReadLine(); + childProcess.BeginErrorReadLine(); + childRunningProcs.Enqueue(childProcess); + } catch (Exception e) { + Log.LogMessage( + MessageImportance.High, + string.Format("Error starting process {0}: {1}", qtCmdCol[1], e.Message)); + ok = false; + } + + while (ok + && (childRunningProcs.Peek().HasExited + || childRunningProcs.Count >= MaxProcs)) { + var childRunningProcess = childRunningProcs.Dequeue(); + childRunningProcess.WaitForExit(); + int exitCode = childRunningProcess.ExitCode; + childRunningProcess.Close(); + if (exitCode != 0) + ok = false; + } + } + + foreach (var childRunningProcess in childRunningProcs) { + childRunningProcess.WaitForExit(); + int exitCode = childRunningProcess.ExitCode; + childRunningProcess.Close(); + if (exitCode != 0) { + ok = false; + } + } + + if (!ok) + return false; + + ]]> + + + + + + + + + + + true + + + + + + $(CleanDependsOn); + QtClean; + + + + + + diff --git a/src/qtmsbuild/qtmoc.xml b/src/qtmsbuild/qtmoc.xml new file mode 100644 index 00000000..11cfb36c --- /dev/null +++ b/src/qtmsbuild/qtmoc.xml @@ -0,0 +1,244 @@ + + + + + + + + + + moc.exe + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + diff --git a/src/qtmsbuild/qtrcc.xml b/src/qtmsbuild/qtrcc.xml new file mode 100644 index 00000000..82dea845 --- /dev/null +++ b/src/qtmsbuild/qtrcc.xml @@ -0,0 +1,270 @@ + + + + + + + + + + rcc.exe + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + + diff --git a/src/qtmsbuild/qtuic.xml b/src/qtmsbuild/qtuic.xml new file mode 100644 index 00000000..14cf279d --- /dev/null +++ b/src/qtmsbuild/qtuic.xml @@ -0,0 +1,190 @@ + + + + + + + + + + uic.exe + + + + + + + + + + + + + + + + + + + + + + + + Execute Before + + + Specifies the targets for the build customization to run before. + + + + + + + + + + + Execute After + + + Specifies the targets for the build customization to run after. + + + + + + + + + + + + + Additional Options + + + Additional Options + + + + + + + + diff --git a/src/qttemplates/console/console.vcxproj b/src/qttemplates/console/console.vcxproj index 0582df26..7e36610f 100644 --- a/src/qttemplates/console/console.vcxproj +++ b/src/qttemplates/console/console.vcxproj @@ -24,6 +24,18 @@ v$PlatformToolset$ + + $(Registry:HKEY_CURRENT_USER\Environment@QtMsBuild) + + + + + + + @@ -34,6 +46,9 @@ + + + \ No newline at end of file diff --git a/src/qttemplates/designer/designer.vcxproj b/src/qttemplates/designer/designer.vcxproj index ce21d976..af9a2245 100644 --- a/src/qttemplates/designer/designer.vcxproj +++ b/src/qttemplates/designer/designer.vcxproj @@ -24,6 +24,18 @@ v$PlatformToolset$ + + $(Registry:HKEY_CURRENT_USER\Environment@QtMsBuild) + + + + + + + @@ -40,6 +52,9 @@ + + + \ No newline at end of file diff --git a/src/qttemplates/gui/gui.vcxproj b/src/qttemplates/gui/gui.vcxproj index 96d716a3..5be7bbca 100644 --- a/src/qttemplates/gui/gui.vcxproj +++ b/src/qttemplates/gui/gui.vcxproj @@ -24,6 +24,18 @@ v$PlatformToolset$ + + $(Registry:HKEY_CURRENT_USER\Environment@QtMsBuild) + + + + + + + @@ -42,6 +54,9 @@ + + + \ No newline at end of file diff --git a/src/qttemplates/lib/lib.vcxproj b/src/qttemplates/lib/lib.vcxproj index 0116af43..97054d33 100644 --- a/src/qttemplates/lib/lib.vcxproj +++ b/src/qttemplates/lib/lib.vcxproj @@ -24,6 +24,18 @@ v$PlatformToolset$ + + $(Registry:HKEY_CURRENT_USER\Environment@QtMsBuild) + + + + + + + @@ -42,6 +54,9 @@ $precompiledsource$ + + + \ No newline at end of file diff --git a/src/qttemplates/server/server.vcxproj b/src/qttemplates/server/server.vcxproj index dc099046..38019e3a 100644 --- a/src/qttemplates/server/server.vcxproj +++ b/src/qttemplates/server/server.vcxproj @@ -24,6 +24,18 @@ v$PlatformToolset$ + + $(Registry:HKEY_CURRENT_USER\Environment@QtMsBuild) + + + + + + + @@ -41,6 +53,9 @@ + + + \ No newline at end of file diff --git a/src/qtvstools/QtVsTools.csproj b/src/qtvstools/QtVsTools.csproj index a5c8c89a..c76b8607 100644 --- a/src/qtvstools/QtVsTools.csproj +++ b/src/qtvstools/QtVsTools.csproj @@ -164,6 +164,31 @@ Always true + + QtMsBuild\qt.props + Always + true + + + QtMsBuild\qt.targets + Always + true + + + QtMsBuild\qtmoc.xml + Always + true + + + QtMsBuild\qtrcc.xml + Always + true + + + QtMsBuild\qtuic.xml + Always + true + Always true diff --git a/src/qtvstools/Vsix.cs b/src/qtvstools/Vsix.cs index f96bf7e1..b88791f3 100644 --- a/src/qtvstools/Vsix.cs +++ b/src/qtvstools/Vsix.cs @@ -43,6 +43,7 @@ namespace QtVsTools [InstalledProductRegistration("#110", "#112", "2.1.2", IconResourceID = 400)] [ProvideMenuResource("Menus.ctmenu", 1)] [ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)] + [ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.NoSolution)] public sealed class Vsix : Package { /// @@ -115,6 +116,16 @@ namespace QtVsTools var uri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase); PkgInstallPath = Path.GetDirectoryName(Uri.UnescapeDataString(uri.AbsolutePath)) + @"\"; + Environment.SetEnvironmentVariable( + "QtVsTools", + PkgInstallPath, + EnvironmentVariableTarget.User); + + Environment.SetEnvironmentVariable( + "QtMsBuild", + Path.Combine(PkgInstallPath, "QtMsBuild"), + EnvironmentVariableTarget.User); + var vm = QtVersionManager.The(); var error = string.Empty; if (vm.HasInvalidVersions(out error)) -- cgit v1.2.3