目前在我的应用我只是有一个单一的源代码树C++单独的Include和源目录和#INCLUDE
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
| |-...
...
但是我希望做一个插件系统(这样少的东西是与核心应用程序的一部分清晰的边界),我想移动到单独的Include \ MyApp树中的那么多.hpp文件。所以新的树可能看起来像:
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 /放在包含路径中,但是Id仍然需要全部组件路径”? – downhillFromHere 2014-09-11 07:54:51
因此,对于说ComponentThing.cpp我不需要一些包括像“../../Include/MyApp/Component/ComponentThing.hpp”的垃圾,但我仍然需要“组件/ ComponentThing.hpp”,而不是只是“ ComponentThing.hpp“ – 2014-09-11 09:29:22