将目录从源树复制到二叉树.例如:如何将www复制到bin文件夹.
work
??bin
??src
??doing
? ??www
??include
??lib
Run Code Online (Sandbox Code Playgroud)
谢谢.
小智 119
从2.8版开始,file命令有一个copy参数:
file(COPY yourDir DESTINATION yourDestination)
Run Code Online (Sandbox Code Playgroud)
注意:
相对于当前源目录评估相对输入路径,并且相对于当前构建目录评估相对目的地
Chi*_*ang 35
使用CMake 2.8,使用file(COPY ...)命令.
对于较旧的CMake版本,此宏将文件从一个目录复制到另一个目录.如果您不想替换复制文件中的变量,请更改configure_file @ONLY参数.
# Copy files from source directory to destination directory, substituting any
# variables. Create destination directory if it does not exist.
macro(configure_files srcDir destDir)
message(STATUS "Configuring directory ${destDir}")
make_directory(${destDir})
file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
foreach(templateFile ${templateFiles})
set(srcTemplatePath ${srcDir}/${templateFile})
if(NOT IS_DIRECTORY ${srcTemplatePath})
message(STATUS "Configuring file ${templateFile}")
configure_file(
${srcTemplatePath}
${destDir}/${templateFile}
@ONLY)
endif(NOT IS_DIRECTORY ${srcTemplatePath})
endforeach(templateFile)
endmacro(configure_files)
Run Code Online (Sandbox Code Playgroud)
Set*_*son 26
该configure命令仅在cmake运行时复制文件.另一种选择是创建新目标,并使用custom_command选项.这是我使用的一个(如果你不止一次运行它,你将不得不修改该add_custom_target行以使其对每个调用都是唯一的).
macro(copy_files GLOBPAT DESTINATION)
file(GLOB COPY_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${GLOBPAT})
add_custom_target(copy ALL
COMMENT "Copying files: ${GLOBPAT}")
foreach(FILENAME ${COPY_FILES})
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
set(DST "${DESTINATION}/${FILENAME}")
add_custom_command(
TARGET copy
COMMAND ${CMAKE_COMMAND} -E copy ${SRC} ${DST}
)
endforeach(FILENAME)
endmacro(copy_files)
Run Code Online (Sandbox Code Playgroud)
juz*_*lin 19
由于没有人提到cmake -E copy_directory作为自定义目标,这就是我使用过的:
add_custom_target(copy-runtime-files ALL
COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/runtime-files-dir ${CMAKE_BINARY_DIR}/runtime-files-dir
DEPENDS ${MY_TARGET})
Run Code Online (Sandbox Code Playgroud)
Jia*_*ian 15
使用execute_process并调用cmake -E.如果需要深层复制,可以使用该copy_directory命令.更好的是,您可以symlink使用create_symlink命令创建(如果您的平台支持它).后者可以像这样实现:
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/path/to/www
${CMAKE_BINARY_DIR}/path/to/www)
Run Code Online (Sandbox Code Playgroud)
来自:http://www.cmake.org/pipermail/cmake/2009-March/028299.html