我是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 ;
答案 0 :(得分:15)
您可以使用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)