当两个子目录引用同一库时,如何正确编写cmake文件?

发布于 2025-02-07 19:35:50 字数 381 浏览 0 评论 0原文

我有这样的目录结构

external/
   loglib/

subdir1/
   CMakeList.txt // link with loglib 
subdir2/
   CMakeList.txt // link with loglib , the same loglib.
main.cc
CMakeList.txt // link with subdir1 subdir2 as if they are isolated libs

loglib因此而重复?这样做的最佳做法是什么?我是否应该将功能仅在主cmakefile下(只能链接loglib一次),然后忘记诸如addSubDirectory之类的隔离?

I have a directory structure like this

external/
   loglib/

subdir1/
   CMakeList.txt // link with loglib 
subdir2/
   CMakeList.txt // link with loglib , the same loglib.
main.cc
CMakeList.txt // link with subdir1 subdir2 as if they are isolated libs

will loglib be duplicated as a consequence of this? what's the best practice to do this? should i just combine the functionality under the main CMakefile (which will only link loglib once ) and forget about isolation such as addsubdirectory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文