问题
Using the Qt Visual studio plugin it seems to take care of most of almost everything in a seemless manner. Unfortunately it does the moc'ing using a CustomBuild step in msbuild. This results in a serial moc'ing, one after another. Is there a way to convince msbuild to do them in parallel - I'm tired of 7 cores sitting on their laurels like me.
I've seen msbuild's BuildInParallel, but I'm not sure how to make that apply here.
msbuild snippet:
<Project>
...
<ItemGroup>
<CustomBuild Include="a_class4.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I."</Command>
</CustomBuild>
<CustomBuild Include="a_class3.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I."</Command>
</CustomBuild>
</ItemGroup>
...
</Project>
回答1:
You can build in parallel using jom
:
http://labs.qt.nokia.com/2009/03/27/speeding-up-visual-c-qt-builds/
回答2:
I am not very familiar with Visual Studio projects ... so don't know if the "CustomBuild" ItemGroup name and its metadata names bear significance. If they do, you might need to
- Modify the ItemGroup name to something else
- Identify the msbuild targets file which handles that and fix it for parallel processing
Here is a standalone msbuild file that can execute things in parallel.
Notes:
- The
ping -n 30 -w 1000 127.0.0.2>nul
command has been added so that I could launch process explorer and find enough time to count how many instances of ping.exe were spawned. - I was trying to ping 127.0.0.2 because I wanted ping not to finish earlier.
- There is nothing practically useful happening in the file ... only echoing properties as a proof of concept.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="RunMe">
<ItemGroup>
<CustomBuild Include="a_class4.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I."</Command>
</CustomBuild>
<CustomBuild Include="a_class3.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I."</Command>
</CustomBuild>
</ItemGroup>
<Target Name="RunMe">
<Message Text="First populate an ItemGroup such that we can use it for parallel processing"/>
<ItemGroup>
<InputForParallelInvoke Include="$(MSBuildThisFileFullPath)">
<Properties>InputFile=%(CustomBuild.Identity);
AdditionalInputs=%(CustomBuild.AdditionalInputs);
Message=%(CustomBuild.Message);
Outputs=%(CustomBuild.Outputs);
Command=%(CustomBuild.Command)</Properties>
</InputForParallelInvoke>
</ItemGroup>
<MSBuild Projects="@(InputForParallelInvoke)" Targets="InvokeInParallel" BuildInParallel="True" />
</Target>
<Target Name="InvokeInParallel">
<Exec Command="ping -n 30 -w 1000 127.0.0.2>nul & echo Properties=$(InputFile) ##### $(AdditionalInputs) ##### $(Message) ##### $(Outputs) ##### $(Command)"/>
</Target>
</Project>
When I invoke it on via msbuild thus msbuild /m \path\to\file /p:Configuration=Debug;Platform=Win32
I see 2 instances of ping.exe.
Hope this helps solve your problem.
来源:https://stackoverflow.com/questions/11236522/qt-mocing-multiple-files-in-parallel-under-msbuild