CMake Custom Command Copy Multiple Files
Answer :
I did it with a loop
# create a list of files to copy set( THIRD_PARTY_DLLS C:/DLLFOLDER/my_dll_1.dll C:/DLLFOLDER/my_dll_2.dll ) # do the copying foreach( file_i ${THIRD_PARTY_DLLS}) add_custom_command( TARGET ${VIEWER_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy ${file_i} "C:/TargetDirectory" ) endforeach( file_i )
Copying multiple files is available from CMake 3.5
cmake -E copy <file>... <destination>
"cmake -E copy" support for multiple files
Command-Line Tool Mode
A relatively simple workaround would be to use ${CMAKE_COMMAND} -E tar
to bundle the sources, move the tarball and extract it in the destination directory.
This could be more trouble than it's worth if your sources are scattered across many different directories, since extracting would retain the original directory structure (unlike using cp
). If all the files are in one directory however, you could achieve the copy in just 2 add_custom_command
calls.
Say your sources to be moved are all in ${CMAKE_SOURCE_DIR}/source_dir
, the destination is ${CMAKE_SOURCE_DIR}/destination_dir
and your list of filenames (not full paths) are in ${FileList}
. You could do:
add_custom_command( TARGET MyExe POST_BUILD COMMAND ${CMAKE_COMMAND} -E tar cfj ${CMAKE_BINARY_DIR}/temp.tar ${FileList} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/source_dir) add_custom_command( TARGET MyExe POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/temp.tar temp.tar COMMAND ${CMAKE_COMMAND} -E tar xfj temp.tar ${FileList} COMMAND ${CMAKE_COMMAND} -E remove temp.tar WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/destination_dir)
Comments
Post a Comment