[CMake] add_custom_target and output file dependencies
Clifford Yapp
cliffyapp at gmail.com
Thu Feb 10 11:01:04 EST 2011
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})
More information about the CMake
mailing list