CMake 安装头文件并维护目录层次结构 [英] CMake install header files and maintain directory heirarchy

查看:21
本文介绍了CMake 安装头文件并维护目录层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 cmake 2.8

Using cmake 2.8

我想在将头文件从源目录复制到目标目录的同时维护目录层次结构.比如需要复制的头文件是abc/1.h, def/2.h 并且它们也应该直接复制到目的地中的相同顺序(通过 CMAKE_INSTALL_PREFIX 设置)

I would like to maintain the directory heirarchy while copying the header files from the source to the destination directory. For example, the header file that needs to be copied are abc/1.h, def/2.h and they should also be copied in the same order in the destination directly ( set via CMAKE_INSTALL_PREFIX )

这是我试过的,但它只是复制头文件而不是头文件,包括父目录名

This is what I have tried, but it just copies the header files and not the header files inclusive parent directory name

set(HEADERS "abc/1.h;def/2.h")
install(FILES ${HEADERS} DESTINATION include)

最终输出应该是 dest_directory/abc/1.h 和 dest_directory/def/2.h.

The final output should be dest_directory/abc/1.h and dest_directory/def/2.h.

推荐答案

如果你的安装目录中有很多文件,你可以考虑使用install(DIRECTORY)安装目录 命令流程.您可以使用 PATTERNREGEX 选项选择应安装目录中的哪些文件:

If you have many files in the directory for install, you may consider to install the directory with install(DIRECTORY) command flow. You may select which files in the directory should be installed with PATTERN or REGEX options:

install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory
        DESTINATION "include" # target directory
        FILES_MATCHING # install only matched files
        PATTERN "*.h" # select header files
)

请参阅 CMake 文档,了解有关安装(目录).此外,它描述了源目录末尾的/"含义.

See CMake documentation for more information about the install(DIRECTORY). Also, it describes meaning '/' at the end of source directory.

这篇关于CMake 安装头文件并维护目录层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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