【发布时间】:2019-11-18 12:20:18
【问题描述】:
我有一个具有以下文件结构的项目(转换到 CMake),源文件和头文件位于同一目录中:
root
+- module1
+- a.hpp
+- a.cpp
+- b.hpp
+- b.cpp
+ module1a
+- a.hpp
+- b.cpp
+- module2
+- a.hpp
+- a.cpp
头文件作为#include<projectname/module1/a.hpp> 包含在彼此中。在构建 .cpp 文件之前,如何指示 CMake 将所有标头作为此结构安装到构建目录中?我简要地查看了install(DIRECTORY "${CMAKE_SOURCE_DIR}/module1" DESTINATION "projectname/module1" FILES_MATCHING PATTERN "*.hpp")(来自CMake install header files and maintain directory heirarchy),但它确实将这些标头安装到构建目录中(没有任何反应)。
仅在编译时需要标头,在运行时不需要。
我能得到一些提示吗?
编辑: 源代码三中的目录布局与 #include 指令包含它的方式不同。例如,考虑#include<projectname/module1a/a.hpp>。 include_directories 不适用于此标头。 #include<projectname/module1/a.hpp 与 root!=projectname 相同。标题必须首先从旧布局复制/符号链接到新布局。
【问题讨论】:
-
您必须使用
include_directories(/path/to/the/headers)来提供构建的标头。 -
不幸的是第一个组件不一样,否则我只会使用
root/..作为包含路径(rootvs.projectname)。 -
不明白。可能我不明白你的项目结构。但是您可以根据需要添加尽可能多的 include_directories。
-
标头包含为
#include<projectname/module/header.hpp>。所以我需要在某处创建projectname目录,然后将所有标头复制/符号链接到其中(或符号链接模块子目录)。没有我可以放入include_directories的目录。 -
"* 它似乎不能满足我的需要*"... 为什么这不是您需要的?如果不是这个,你想达到什么目的?为什么不直接使用
include_directories()将标题包含到您的项目中?为什么include_directories()不起作用?
标签: cmake header-files