I have a project built with CMake that needs to copy some resources to the destination folder. Currently I use this code:
我有一个使用CMake构建的项目,需要将一些资源复制到目标文件夹。目前我使用此代码:
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 to duplicate the lengthy custom command.
现在我想从不同的文件夹中复制更多文件。因此,我们希望将文件从path / to / files和path / to / files2复制到二进制文件夹中的相同位置。一种方法是复制上面的代码,但似乎没有必要复制冗长的自定义命令。
Is there an easy way to use file
(and possibly the list
command as well) to concatenate two GLOB
lists?
有没有一种简单的方法来使用文件(也可能是list命令)来连接两个GLOB列表?
2 个解决方案
#1
28
The file(GLOB ...)
command allows for specifying multiple globbing expressions:
文件(GLOB ...)命令允许指定多个globbing表达式:
file(GLOB files "path/to/files/*" "path/to/files2*")
#2
23
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})
#1
28
The file(GLOB ...)
command allows for specifying multiple globbing expressions:
文件(GLOB ...)命令允许指定多个globbing表达式:
file(GLOB files "path/to/files/*" "path/to/files2*")
#2
23
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})