(c)make - 递归编译
假设我有这样的目录:
dir1
main.cpp
dir2
abc.cpp
dir3
def.cpp
dir4
ghi.cpp
jkl.cpp
假设 main.cpp 包括 dir2/abc.cpp 和 dir3/def.cpp,def.cpp 包括 dir4/ghi.cpp 和 dir4/jkl.cpp。
我的问题是,如何在 dir1/ 中拥有 one Makefile/CMakeLists.txt ,它递归地进入每个目录并编译 *.cpp,然后“加入”它们?
抱歉我的英语不好,希望我能很好地解释我的问题!
谢谢!
Let's assume I have directories like:
dir1
main.cpp
dir2
abc.cpp
dir3
def.cpp
dir4
ghi.cpp
jkl.cpp
And let's assume that main.cpp includes dir2/abc.cpp and dir3/def.cpp, def.cpp includes dir4/ghi.cpp and dir4/jkl.cpp.
My question is, how can I have one Makefile/CMakeLists.txt in dir1/ which goes in each directory recursively and compiles *.cpp, and then "joins" them?
Sorry for my english, hope that I explained my question well!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 makefile,dir1/Makefile 应该:
至于 cmake,它“自动检测此类依赖关系” “(二进制依赖于 dir2/abc.o 和 dir3/def.o),所以实际上你不需要关心它。
For makefile, dir1/Makefile should:
As for cmake it detects such dependencies "automatically" (binary depended on dir2/abc.o and dir3/def.o), so virually you don't need care about it.
一个 CMakeLists.txt 文件:
我不确定“加入”源是什么意思。我在这里假设您将它们组合到库或可执行文件中。
One CMakeLists.txt file:
I am unsure what you mean by "joining" the sources. I am assuming here that you are combining them into either a library or an executable.
递归 make 是否是一件好事存在着一个公开的争论。请参阅此博客文章,了解相对较新的调查最新的赞成和反对论文。
There is an open argument whether recursive make is a good thing. Please see this blog entry for a survey of relatively up-to-date pro and con papers.