cmake拷贝文件夹的方法

cmake拷贝文件夹

  • 使用add_custom_target完成拷贝
  • 下面的核心代码, 以VS2015为例,将会创建一个名为copy_files的项目,见下图:

核心代码范例

# 拷贝文件夹到指定的目录
add_custom_target(copy_files ALL  
  VERBATIM 
  # COMMAND_EXPAND_LISTS 
  COMMAND ${CMAKE_COMMAND} -E make_directory "${publih_lib_include}" 
  COMMAND ${CMAKE_COMMAND} -E 
                  copy_directory  
                  "${CMAKE_CURRENT_SOURCE_DIR}/include" 
                  "${publih_lib_include}" 
) 

  • copy_files是创建的项目名称,可任意修改
  • publih_lib_include为自定义输出目录

代码解释

COMMAND ${CMAKE_COMMAND} -E make_directory "${publih_lib_include}" 
  • 创建${publih_lib_include}宏所在目录
  COMMAND ${CMAKE_COMMAND} -E 
                  copy_directory  
                  "${CMAKE_CURRENT_SOURCE_DIR}/include" 
                  "${publih_lib_include}" 
  • "${CMAKE_CURRENT_SOURCE_DIR}/include"文件夹拷贝到"${publih_lib_include}"

add_custom_target 更多用法

posted @ 2022-03-03 00:25  mohist  阅读(4381)  评论(0编辑  收藏  举报