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 )
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to