[CMake] add_custom_target and output file dependencies

David Cole david.cole at kitware.com
Thu Feb 10 11:19:57 EST 2011


Are you using "make -j" for parallel builds by any chance? Does it still
happen if you use make without any -j flags...?

Rather than:
     ADD_CUSTOM_COMMAND(
        OUTPUT ${outputlist}
        COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.cmake
        DEPENDS ${${datalist}}

I would recommend changing to:
     ADD_CUSTOM_COMMAND(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.sentinel
        COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.cmake
        COMMAND ${CMAKE_COMMAND} -E
${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.sentinel
        DEPENDS ${${datalist}}

And then change anything that depends on ${outputlist} (if anything) to
depend on the sentinel file instead...

We use the "single output sentinel file" approach with the
ExternalProject_Add custom commands, and it works very well.

Perhaps multiple cmakes are trying to copy the same file at the same time
because of parallel building and multiple outputs being specified for the
add_custom_command call.... (Speculation) But if true, this might be a
reasonable explanation. If not, it's a mystery then....

Do you see any error output...? What is the "not terminating" thing: is it
that make never comes back, or that you have a zombie cmake process after
running make...?



On Thu, Feb 10, 2011 at 11:01 AM, Clifford Yapp <cliffyapp at gmail.com> wrote:

> On Thu, Feb 10, 2011 at 10:48 AM, David Cole <david.cole at kitware.com>
> wrote:
> > Show us the surrounding code (i.e. -- the actual copy command)
>
> <nods> - sorry, should have provided more detail.
>
> This is an example file that does the copying:
>
>      SET(FILES_TO_COPY
>
> /home/user/brlcad/cmake/src/tclscripts/ami.tcl;/home/user/brlcad/cmake/src/tclscripts/ampi.tcl;/home/user/brlcad/cmake/src/tclscripts/cad_clrpick.tcl;/home/user/brlcad/cmake/src/tclscripts/cad_dialog.tcl;/home/user/brlcad/cmake/src/tclscripts/chkexterns.tcl;/home/user/brlcad/cmake/src/tclscripts/
> fs_dialog.tk
> ;/home/user/brlcad/cmake/src/tclscripts/helpcomm.tcl;/home/user/brlcad/cmake/src/tclscripts/helplib.tcl;/home/user/brlcad/cmake/src/tclscripts/hoc.tcl;/home/user/brlcad/cmake/src/tclscripts/html_library.tcl;/home/user/brlcad/cmake/src/tclscripts/libdm.tcl;/home/user/brlcad/cmake/src/tclscripts/menu_override.tcl;/home/user/brlcad/cmake/src/tclscripts/mouse.tcl;/home/user/brlcad/cmake/src/tclscripts/vmath.tcl)
>      FILE(COPY ${FILES_TO_COPY} DESTINATION
> /home/user/brlcad/cmake-build/share/brlcad/7.18.1/tclscripts)
>
> This is the subset of the macro that generates the files:
>
>     SET(inputlist)
>      FOREACH(filename ${${datalist}})
>         SET(inputlist ${inputlist} ${CMAKE_CURRENT_SOURCE_DIR}/${filename})
>      ENDFOREACH(filename ${${datalist}})
>      SET(${targetprefix}_cmake_contents "
>      SET(FILES_TO_COPY ${inputlist})
>      FILE(COPY \${FILES_TO_COPY} DESTINATION
> ${CMAKE_BINARY_DIR}/${DATA_DIR}/${targetdir})
>      ")
>      FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.cmake
> "${${targetprefix}_cmake_contents}")
>      SET(outputlist)
>      FOREACH(filename ${${datalist}})
>         GET_FILENAME_COMPONENT(ITEM_NAME ${filename} NAME)
>         SET(outputlist ${outputlist}
> ${CMAKE_BINARY_DIR}/${DATA_DIR}/${targetdir}/${ITEM_NAME})
>      ENDFOREACH(filename ${${datalist}})
>      ADD_CUSTOM_COMMAND(
>         OUTPUT ${outputlist}
>         COMMAND ${CMAKE_COMMAND} -P
> ${CMAKE_CURRENT_BINARY_DIR}/${targetprefix}.cmake
>         DEPENDS ${${datalist}}
>         )
>      ADD_CUSTOM_TARGET(${datalist}_cp ALL DEPENDS ${outputlist})
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110210/a41a2219/attachment.htm>


More information about the CMake mailing list