Qt MOC multiple files in parallel with MSBuild

Good morning!

I know that this question already exists here: Qt Moc'ing of several files in parallel in msbuild , but I would not raise this old question.

I work in Visual Studio 2010, and I need to speed up the compilation time of my application. I use all flags, such as /MP with MSBuild -j with Make, etc. The last optimization step is to parallelize the MOC'ing steps. They are painfully slow, and I google a lot, and I did not find a solution.

I know jom exists, but it uses nmake, and I have to use MSBuild.

If someone has already heard the solution, this should be really cool!

Have a nice day!

+6
source share
1 answer

If you create a VC project file with qmake from qt * .pro, it generates it in such a way that mocables are compiled in a single thread. The only way I know to get around this behavior is to explicitly call jom to preprocess the moc.

I only have VS2012 (win32-msvc2012), but I used a similar thing for VS2010 (win32-msvc2010 in your case)

To do this, you need to automate the following steps:

Create a VC project from the pro file via qmake:

 qmake -spec win32-msvc2012 -tp vc -o ${path-to-target}/${your-project}.vcxproj ${path-to-source}/${your-qt-pro}.pro 

Create a make file from the pro file via qmake:

 qmake -spec win32-msvc2012 CONFIG+=release -o ${path-to-target}/Makefile', ${path-to-source}/${your-qt-pro}.pro 

Create the following .bat file next to the vcproj file (put% VS100COMNTOOLS% for vc2010 and x86 / x64 for the arch):

 call "%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" ${arch} md build\release\generated ${environment.dir}\bin\jom.exe -j 16 /F Makefile.release mocables 

To debug, change 'release' to 'debug' (or enter a variable)

Now you need to edit the VC project file. Here is what you need to find / replace (using regular expressions):

1) For all includes (tags Project-> ItemGroup-> CustomBuild Include, containing * .h files:

  • find: </CustomBuild>
  • replace with: <ExcludedFromBuild>true</ExcludedFromBuild> </CustomBuild>

2) for Project-> ItemDefinitionGroup:

  • find: </Link>
  • replace with: </Link> <PreBuildEvent> <Command>build_moc.bat</Command> </PreBuildEvent>

3) for Project-> ItemDefinitionGroup: - find: <ItemDefinitionGroup> - replace with: <Target Name="BeforeClean"> <Message Text="Cleaning moc generated files"/> <Exec Command="del \$\(ProjectDir\)..\\\$(Platform\)\\build\\${arch}\\generated\\moc_*.* /F /Q" /> </Target> <ItemDefinitionGroup>

I am automating it with Maven, so here is the code snippet for the link:

build_moc.bat:

 cd %1 md build\%2\generated c:\\develop\\buildenv\bin\jom.exe -j 16 /F Makefile.%2 mocables 

maven script that performs replacements (maven-replacer-plugin configuration):

 <!-- Disabling moc preprocessor steps, since we do it with jom --> <replacement> <xpath>//Project/ItemGroup/CustomBuild[contains(@Include,'.h')]</xpath> <token><![CDATA[</CustomBuild>]]></token> <value><![CDATA[ <ExcludedFromBuild>true</ExcludedFromBuild> </CustomBuild> ]]></value> </replacement> <!-- Adding moc preprocessor steps with jom --> <replacement> <xpath>//Project/ItemDefinitionGroup[not(@*)]</xpath> <token><![CDATA[</Link>]]></token> <value><![CDATA[ </Link> <PreBuildEvent> <Command>\$\(ProjectDir\)../${arch}/build_moc.bat \$\(ProjectDir\)../${arch} \$\(Configuration\)</Command> </PreBuildEvent> ]]></value> </replacement> <!-- Cleaning moc files --> <replacement> <token><![CDATA[<ItemDefinitionGroup>]]></token> <value><![CDATA[ <Target Name="BeforeClean"> <Message Text="Cleaning moc generated files"/> <Exec Command="del \$\(ProjectDir\)..\\\$\(Platform\)\\build\\${arch}\\generated\\moc_*.* /F /Q" /> </Target> <ItemDefinitionGroup> ]]></value> </replacement> 

I hope this helps

+1
source

All Articles