将库链接到cmake项目中的所有目标 [英] link library to all targets in cmake project

查看:93
本文介绍了将库链接到cmake项目中的所有目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我描述一下我认为是足够普遍的用例,应该予以支持。考虑一个项目,该项目由一个库和一组使用该库的可执行文件组成。一种简单的方法是add_library,然后是一系列add_executable()target_link_lib()对。

Let me describe what I think is a sufficiently common use case, that it should be supported. Consider a project which consists of a library and a set of executable that use that library. A straightforward approach is to add_library, followed by a sequence of add_executable() target_link_lib() pairs.

这是很多样板代码。能够执行set(PROJECT_LINK_LIBS,lib1 ...)这样的事情,并让cmake删除多余的样板,这将是很好的。

This is a lot of boilerplate coding. It would be nice to able to do something like set(PROJECT_LINK_LIBS, lib1 ...), and have cmake remove the extra boilerplate.

进一步考虑这一点,我意识到我想要一个link_libraries函数,其功能类似于include_directories。我会认为:

Thinking on this more, I realize I would like a link_libraries function that behaves similarly to include_directories. I would argue that this:


  1. 在很多情况下都会有用。

  2. 会导致来鼓吹CMakeLists。

  3. 将鼓励更好的代码组织-自然地有动机去组织文件夹,代码和可执行文件,使得所有可执行文件都具有相同的依赖关系-

有这样的东西吗?

推荐答案

https://stackoverflow.com/a/50295894/129550 所述现在,请求的 link_libraries(示例example2)函数实际上是cmake的一部分。

As mentioned at https://stackoverflow.com/a/50295894/129550 the requested link_libraries(example example2) function is actually now a part of cmake.

这篇关于将库链接到cmake项目中的所有目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆