[CMake] Parallel make & custom command

Joris Dobbelsteen joris.dobbelsteen at sioux.eu
Wed Jun 29 12:00:26 EDT 2011


On Wed, 2011-06-29 at 17:22 +0200, 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.

I think you should describe your problem a bit more. What are you
exactly doing? Examples from the cmake files will help us.

Do you generate the same file (in the same directory?) by different
tools or are some intermediate files used?
Did you list all the generated files as being created by the single
custom command?

In my case I have a custom command generating multiple files, listing
all the files it generated under that command (and setting their
"generated" property to true). This works very well, even with parallel
builds.

> 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. 

For these tools, you should assume taht anything is run in parallel (and
in arbitrary order), unless (and only unless) there is a dependency.

Generally, not having the dependencies properly in the build scripts
(with makefiles or anything else) will result in errors during parallel
builds that will not happen with sequential builds.

> Am I correct in this assumption? And if so, what's the proper solution
> for this problem?
> 
> Best regards,
> Marcel Loose.
> 

-- 
With kind regards, met vriendelijke groeten, cordialement,

Joris Dobbelsteen
Software Engineer

Sioux Embedded Systems B.V. 
The Netherlands | Visit us at: www.sioux.eu




More information about the CMake mailing list