I am only able to achieve multiple source file compilation within a project and it never compiles all my targets in parallel. Here targets Lib1 Lib2 Lib3 Lib4 targets and they do not dependent on each other. So ideally they should build in parallel.
I opened generate .sln (by cmake for Visual Studio Generator for project) and from there if I select multiple target and bulild them they get build fine.
NOTE: This issue is only present in Visual Studio Generator. For Ninja/xcode it works fine.
Please help me here. Am I doing anything wrong here ? How I can enable multiple projects compiles in parallel using cmake for msbuild prjects?
I have a vague recollection that if you list multiple targets in the cmake --build ... --target command line, it actually builds each target one at a time, not all of them in the one invocation. I could be wrong about that, but please check it. For testing purposes, you could try adding a custom target to your project which depends on Lib1, Lib2, Lib3 and Lib4, then list just that custom target after the --target command line option. If you see a difference in parallelism, that would answer this question.
The other thing I’d recommend is to try the Multi-Tool Task scheduler. It should give you the behavior you’re looking for if my recollection as discussed in the previous paragraph turns out to be incorrect. Re-run the CMake configure step, adding the following to the cmake command line (including the quotes):
D:\TW\Workspace>cmake --build --preset=Windows-x64-Debug --target SampleCustomTarget – /m
MSBuild version 17.5.1+f6fdcf537 for .NET Framework
MSBuild logs and debug information will be at “D:\TW\Builds\TWInt\Windows-x64\MSBuild_Logs”
Checking Build System
Building Custom Rule D:/TW/Workspace/CMakeLists.txt
Building Custom Rule D:/TW/Workspace/CMakeLists.txt
Building Custom Rule D:/TW/Workspace/CMakeLists.txt
Building Custom Rule D:/TW/Workspace/CMakeLists.txt
TWWinUIApp.cpp
TWWinUIApp.cpp
Lib1.vcxproj → D:\TW\Builds\TWLib\Windows-x64\Debug\Lib1.lib
Lib2.vcxproj → D:\TW\Builds\TWLib\Windows-x64\Debug\Lib2.lib
TWWinUIApp.cpp
Lib3.vcxproj → D:\TW\Builds\TWLib\Windows-x64\Debug\Lib3.lib
TWWinUIApp.cpp
Lib4.vcxproj → D:\TW\Builds\TWLib\Windows-x64\Debug\Lib4.lib
Building Custom Rule D:/TW/Workspace/CMakeLists.txt
My earlier comment explained what is likely happening:
If that’s indeed the case, then you will need to avoid listing multiple targets after --target on the command line. My suggestion was to create a custom target that depends on the ones you want built, but you said you are not willing/able to do that. So you’re either stuck with the serial behavior, or you’ll need to find a way to allow you to add such a custom target.