On 2008-10-07 10:22+0200 Martin Apel wrote:
Hi all,I'm experiencing the following problem with ADD_CUSTOM_COMMAND: The commands defined for it are executed multiple times, if multiple targets depend on it and I run a parallel make afterwards. An example makes this easier to understand: PROJECT(Test) cmake_minimum_required(VERSION 2.6) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_BINARY_DIR}/a COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/a) ADD_CUSTOM_TARGET(b COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/b DEPENDS ${CMAKE_BINARY_DIR}/a) ADD_CUSTOM_TARGET(c COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/c DEPENDS ${CMAKE_BINARY_DIR}/a) ADD_CUSTOM_TARGET(world) ADD_DEPENDENCIES(world b) ADD_DEPENDENCIES(world c)
You have run into a CMake limitation which I am told is an inevitable result of their two-tier dependency approach (file dependencies and target dependencies). To avoid the issue you have found for parallel builds you must use the following constraint on your CMake logic. If two targets file depend on the same custom_command output file you must serialize them so they don't interfere with each other in a parallel build. So to bring the above example into compliance with that rule you must ADD_DEPENDENCIES(c b) Don't ask me to justify the above rule (I am not that familiar with how CMake implements its target dependencies and its file dependencies), but I know that the above rule works. PLplot has a huge thicket of file and target dependencies so I have run into this wall any number of times with parallel build problems for various combinations of PLplot build options. So far, I have always been able to find a way to comply with the rule and thus get parallel builds to work again, but it has not been that easy. For projects like PLplot with complicated dependencies and a lot of different user options what we need is a CMake dependency validator to make sure there is a warning message about certain target file dependencies ruling out valid parallel builds when the above rule is broken for the particular collection of options that the user picks. Alan __________________________ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linux-powered Science __________________________ _______________________________________________ CMake mailing list [email protected] http://www.cmake.org/mailman/listinfo/cmake
