[CMake] Parallel make & custom command

Michael Wild themiwi at gmail.com
Wed Jun 29 14:46:19 EDT 2011


On 06/29/2011 05:22 PM, Marcel Loose wrote:
> Hi all,
> 
> I'm having a problem with a parallel 'make' where one or more sources
> are generated by a custom command.
> 
> The situation is as follows. There are a couple of targets (executables)
> that depend on the same source file being generated by a custom
> command. 
> 
> I notice that, when doing a parallel build, the custom command is
> executed multiple times, thereby potentially overwriting or corrupting
> the same file that's generated in different threads.
> 
> My feeling is that this is caused by the fact that CMake generates a
> build.cmake file for each target separately. Hence, when doing a
> parallel build, these build.cmake files are also processed in parallel. 
> 
> Am I correct in this assumption? And if so, what's the proper solution
> for this problem?
> 
> Best regards,
> Marcel Loose.
> 

Yes, I've seen this issue too. The only way I can think of fixing this
is by having a single custom target which depends on the generated
files, and then have the executables using the generated sources depend
on that custom target. This way you force the custom target to be run
first before the other targets, thus avoiding the custom commands
generating the sources from running multiple times.

Michael


More information about the CMake mailing list