[CMake] dependency in custom command?
King, Steven R
steven.r.king at intel.com
Tue Sep 1 00:47:39 EDT 2009
In case it's useful, here's a macro to copy an arbitrary file form the source directory to the binary directory. The dependencies work such that the file is not copied if the destination is up-to-date.
This is working fine for me, but suggested improvements are very welcome.
Thanks,
-steve
#-------------------------------------------------------------------------------------------------
# Macro to copy an arbitrary file from the source directory to the binary directory.
macro( copy_file_from_src_to_bin file_arg )
# Always put the name of a custom command's output into a variable otherwise
# dependency checking doesn't seem to work.
set( SRC_OF_${file_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${file_arg} )
set( DEST_OF_${file_arg} ${CMAKE_CURRENT_BINARY_DIR}/${file_arg} )
# Copy the configuration file to the build directory for use by the test
add_custom_command (
OUTPUT ${DEST_OF_${file_arg}}
COMMAND ${CMAKE_COMMAND} -E copy ${SRC_OF_${file_arg}} ${DEST_OF_${file_arg}}
DEPENDS ${SRC_OF_${file_arg}}
COMMENT "CUSTOM COMMAND: Copy ${file_arg} to build directory."
)
add_custom_target (
copy_file_from_src_to_bin_${file_arg} ALL
DEPENDS ${DEST_OF_${file_arg}}
)
endmacro( copy_file_from_src_to_bin )
More information about the CMake
mailing list