I have a project built with CMake that needs to copy some resources to the destination folder. Currently I use this code:
file(GLOB files "path/to/files/*")
foreach(file ${files})
ADD_CUSTOM_COMMAND(
TARGET MyProject
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${file}" "${CMAKE_BINARY_DIR}/Debug"
)
endforeach()
Now I want to copy more files from a different folder. So we want to copy files from both path/to/files
and path/to/files2
to the same place in the binary folder. One way would be to just duplicate the above code, but it seems unnecessary t开发者_开发技巧o duplicate the lengthy custom command.
Is there an easy way to use file
(and possibly the list
command as well) to concatenate two GLOB
lists?
The file (GLOB ...)
command allows for specifying multiple globbing expressions:
file (GLOB files "path/to/files/*" "path/to/files2*")
Alternatively, use the list (APPEND ...)
sub-command to merge lists, e.g.:
file (GLOB files "path/to/files/*")
file (GLOB files2 "path/to/files2*")
list (APPEND files ${files2})
I'd construct a list for each of the patterns and then concatenate the lists:
file(GLOB files1 "path/to/files1/*")
file(GLOB files2 "path/to/files2/*")
set(files ${files1} ${files2})
精彩评论