要仅复制.xml
和.conf
文件,您可以使用以下file(GLOB ...)
命令:
# Gather list of all .xml and .conf files in "/config"
file(GLOB ConfigFiles ${CMAKE_SOURCE_DIR}/config/*.xml
${CMAKE_SOURCE_DIR}/config/*.conf)
foreach(ConfigFile ${ConfigFiles})
add_custom_command(TARGET MyTarget PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${ConfigFile} $<TARGET_FILE_DIR:MyTarget>)
endforeach()
获取所有不在.svn
子目录中的文件是一个类似的过程:
# Gather list of all files in "/config"
file(GLOB ConfigFiles RELATIVE ${CMAKE_SOURCE_DIR}/config
${CMAKE_SOURCE_DIR}/config/*)
# Gather list of all files in "/config/.svn"
file(GLOB SvnConfigFiles RELATIVE ${CMAKE_SOURCE_DIR}/config
${CMAKE_SOURCE_DIR}/config/.svn/*)
# Remove ".svn" and its contents from the list
list(REMOVE_ITEM ConfigFiles .svn ${SvnConfigFiles})
foreach(ConfigFile ${ConfigFiles})
add_custom_command(TARGET MyTarget PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_SOURCE_DIR}/config/${ConfigFile}
$<TARGET_FILE_DIR:MyTarget>)
endforeach()