【发布时间】:2014-11-05 00:51:41
【问题描述】:
目前在我的应用程序中,我只有一个源代码树
MyApp/Source
|-Precompiled.hpp
|-Precompiled.cpp
|-Thing.hpp
|-Thing.cpp
|-Main.cpp
|-Component
| |-ComponentThing.hpp
| |-ComponentThing.cpp
| |-...
|-ComponentB
| |-ComponentBThing.hpp
| |-...
|-PluginCandiate
| |-PluginThing.hpp
| |-PluginThing.cpp
| |-...
...
但是,我想创建一个插件系统(这样,核心应用程序的一部分就更少了,边界清晰),我想将其中的许多 .hpp 文件移动到单独的 Include\MyApp 树中。所以新树可能看起来像:
MyApp/Include/MyApp
|-Thing.hpp
|-Component
| |-ComponentThing.hpp
| ...
|-ComponentB
| |-ComponentBThing.hpp
MyApp/Source
|-Precompiled.hpp
|-Precompiled.cpp
|-PrivateThing.hpp
|-PrivateThing.cpp
|-Component
| |-ComponentThing.cpp
| |-...
|-ComponentB
| |-...
...
Plugins/PluginCandiate/Source
|-PluginThing.hpp
|-PluginThing.cpp
...
现在使用当前方式,我的包含路径上只有“源”。这意味着例如在ComponentThing.cpp 我可以说:
#include "Precompiled.hpp"
#include "ComponentThing.hpp"
#include "ComponentOtherThing.hpp"
#include "ComponentB/ComponentBThing.hpp"
因为当前目录总是首先在包含路径上。但是,如果我拆分我的公共包含目录和源目录,情况就不再如此了。我可以将 Include/Myapp/ 放在包含路径上,但 Id 仍然需要所有内容的完整组件路径。
有没有一种简单的方法来避免这种情况(使用 MSVC MSBuild 和 Linux make 文件),或者只有完整的#includes 是标准做法?还是人们通常会做其他事情(例如,我考虑了一个从主源代码树“导出”列出的公共标头集的构建后步骤)?
【问题讨论】:
-
您能否详细说明您的意思:“我可以将 Include/Myapp/ 放在包含路径上,但我仍然需要所有内容的完整组件路径”?
-
所以说 ComponentThing.cpp 我不需要像“../../Include/MyApp/Component/ComponentThing.hpp”这样的包含废话,但我仍然需要“Component/ComponentThing .hpp” 而不仅仅是“ComponentThing.hpp”
标签: c++ build msbuild makefile project