6

我正在使用以下自定义命令将目录中的所有文件复制configbuild目录中。问题是我不希望.svn目录也被复制。我正在寻找一种方法来排除.svn目录或复制具有特定扩展名的文件。例如,我只想复制带有xmlconf扩展名的文件。我应该怎么办?

add_custom_command(TARGET MyTarget PRE_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy_directory
                       ${CMAKE_SOURCE_DIR}/config $<TARGET_FILE_DIR:MyTarget>)

相关问题

4

1 回答 1

12

要仅复制.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()
于 2012-11-18T11:20:48.560 回答