使用ExternalProject_Add_Step移动包含文件和子文件夹的文件夹

时间:2015-03-11 16:17:27

标签: cmake

我正在使用ExternalProject_Add_Step。我想将包含源文件和子文件夹的文件夹移动到另一个文件夹。但是ExternalProject_Add_Step似乎不接受'*'。

ExternalProject_Add_Step(
    MonoEngine
    copySource
    WORKING_DIRECTORY ${MONOENGINE_DIR}
    DEPENDEES createFolders
    COMMAND mv MonoEngineSource/* MonoEngine
    COMMENT "Moving src to MonoEngine folder"
)

它说mv: cannot stat ‘MonoEngineSource/src/*’: No such file or directory。如果我用现有文件替换*它可以工作。但我想移动所有文件和子文件夹。

1 个答案:

答案 0 :(得分:2)

您应该能够使用CMake的跨平台command-line tool mode来实现这一目标:

ExternalProject_Add_Step(
    MonoEngine
    copySource
    WORKING_DIRECTORY ${MONOENGINE_DIR}
    DEPENDEES createFolders
    COMMAND ${CMAKE_COMMAND} -E rename MonoEngineSource MonoEngine
    COMMENT "Moving src to MonoEngine folder"
)

如果目标文件夹已存在,则需要分两步执行此操作:

ExternalProject_Add_Step(
    MonoEngine
    copySource
    WORKING_DIRECTORY ${MONOENGINE_DIR}
    DEPENDEES createFolders
    COMMAND ${CMAKE_COMMAND} -E copy_directory MonoEngineSource MonoEngine
    COMMENT "Copying src to MonoEngine folder"
)
ExternalProject_Add_Step(
    MonoEngine
    removeSource
    WORKING_DIRECTORY ${MONOENGINE_DIR}
    DEPENDEES copySource
    COMMAND ${CMAKE_COMMAND} -E remove_directory MonoEngineSource
    COMMENT "Removing MonoEngineSourcefolder"
)