cmake glob包括保留目录结构

时间:2022-09-01 23:34:19

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

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

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

FWIW我试图模仿的bjam命令是

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

1 个解决方案

#1


14  

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

您可以使用CMake install命令的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:

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

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

#1


14  

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

您可以使用CMake install命令的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:

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

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