list 如何将多个文件列表与 CMake 合并在一起?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7533502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I merge multiple lists of files together with CMake?
提问by Calvin
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?
有没有一种简单的方法可以使用file
(也可能是list
命令)来连接两个GLOB
列表?
回答by sakra
The file (GLOB ...)
command allows for specifying multiple globbing expressions:
该file (GLOB ...)
命令允许指定多个 globbing 表达式:
file (GLOB files "path/to/files/*" "path/to/files2*")
Alternatively, use the list (APPEND ...)
sub-command to merge lists, e.g.:
或者,使用list (APPEND ...)
子命令合并列表,例如:
file (GLOB files "path/to/files/*")
file (GLOB files2 "path/to/files2*")
list (APPEND files ${files2})
回答by antonakos
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})