[CMake] dependency in custom command?

Michael Wild themiwi at gmail.com
Tue Sep 1 03:37:08 EDT 2009


On 1. Sep, 2009, at 6:47, King, Steven R wrote:

> 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 )


You are aware that configure_file with the COPYONLY argument does just  
that at CMake-time?

Michael


More information about the CMake mailing list