cmake glob包含,同时保留目录结构 [英] cmake glob include while preserving directory structure

查看:106
本文介绍了cmake glob包含,同时保留目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 cmake 的新手,我试图安装 .hpp 文件,同时保留目录结构。

I'm new to cmake and I'm trying to install .hpp files while preserving directory structure.

到目前为止,我有

FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/include/MyLib/*.hpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/include/MyLib/detail/*.hpp"

install (FILES ${files}  DESTINATION include)

找到所有文件,但

FWIW我要模拟的 bjam 命令是

FWIW The bjam command I'm trying to emulate is

install headers 
    : ../include/EnsembleLearning.hpp  
      [ glob ../include/MyLib/*.hpp ]  
      [ glob ../include/MyLib/detail/*.hpp ]  
    : <install-source-root>../include ;


推荐答案

您可以使用CMake的DIRECTORY变体安装命令。此命令将保留复制目录的结构:

You can use the DIRECTORY variant of the CMake install command. This command will preserve the structure of the copied directory:

install(DIRECTORY include/ DESTINATION include
          FILES_MATCHING PATTERN "*.hpp")

如果要复制的目录包含不应安装的子目录,您将必须明确排除具有PATTERN EXCLUDE选项的用户:

If the directory to be copied contains subdirectories that should not be installed, you'll have to explicitly exclude those with a PATTERN EXCLUDE option:

install(DIRECTORY include/ DESTINATION include
          FILES_MATCHING PATTERN "*.hpp"
          PATTERN "include/MyOtherLib" EXCLUDE)

这篇关于cmake glob包含,同时保留目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆