cmake glob include 同时保留目录结构

发布于 2024-11-13 08:05:35 字数 619 浏览 4 评论 0原文

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

到目前为止,我已

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 命令是

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

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

So far I have

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)

All the files get found but the directory hierarchy is flattened.

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 ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-11-20 08:05:35

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

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

如果要复制的目录包含不应安装的子目录,则必须使用 PATTERN EXCLUDE 选项显式排除这些子目录:

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

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")

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文