#include 使用 autotools 进行依赖管理

#include dependencies management with autotools

我编写一些 C++ 软件并使用 GNU autotools 管理整个项目。

我有一些 C++ 代码非常冗长,所以我制作了一个脚本 "generator.rb",它会在文件 "generated.cpp".

中自动生成它

我有一个构建目标 "generated.cpp" 从 "object_list.txt"

构建 "generated.cpp"

到目前为止一切正常。

现在我想将这个 "generated.cpp" 文件#include 到另一个 "handwritten.cpp" 中。

因为据说 automake 会自动计算包含文件的依赖关系,我希望它:

那我该怎么做呢?

备注:我的源代码树是这样的:

./
\_src/
|  \_handwritten.cpp
|_design/
|  \_object_list.txt
\_tools/
   \_generator.rb  

备注:我的构建树是这样的:

build/
 \_gcc_debug/
    |_src/
    |  \_handwritten.o
    \_design/
       \_generated.cpp

Since automake is said to automaticaly compute the dependencies on included files

由于 Automake 生成的 Makefile 生成依赖项作为编译的副作用,因此作为构建的一部分创建的文件需要特殊处理。在尝试任何正常编译之前,您必须告诉 Automake 构建这样的文件。这是使用 BUILT_SOURCES 完成的,例如:

BUILT_SOURCES = generated.cpp

... 然后编写您需要创建的规则 generated.cpp.