cmake,add_subdirectory而不将其添加到生成的项目文件中?

发布于 11-28 11:36 字数 310 浏览 2 评论 0原文

我有一个使用 cmake 构建的项目。在我的 cmakelists 中我有一个 add_subdirectory(externals/foo) 构建具有自己的 cmakelists 的依赖项“foo”。

现在,整个 foo 源代码和标头也包含在生成的项目文件中(我使用的是 Eclipse)。但我想要的只是让我的项目在 Eclipse 中可用(Eclipse 在同一文件夹结构中存在子项目问题)。 因此,“foo”中的 cmakelists 仅用于自动构建“foo”并将其链接到我的项目。但我不想在我的 IDE 中看到它。

这可能吗?如果是:如何?

I have a project that is build with cmake. In my cmakelists I have a
add_subdirectory(externals/foo)
to build the dependency "foo" which has it's own cmakelists.

Now it is so that also the whole foo sources and headers are included in the generated Project file (I'm using Eclipse). But all I want is to only have my project available in Eclipse (Eclipse has problems with subprojects in the same folder structure).
So that the cmakelists from "foo" is only used to build "foo" automatically and link it to my project. I don't want to see it in my IDE however.

Is this possible? If yes: How?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏半生如梦愿梦如真2024-12-05 11:36:43

当我将 Eclipse 与 CMake 结合使用时,我手动创建 Eclipse 项目(使用“新建项目”向导),对于 CMake,我使用标准 makefile 生成器。它需要一些额外的设置:如果您正在进行源外构建,则需要在项目属性中设置构建目录,我通常将构建命令设置为 make VERBOSE=1

我不确定,因为我没有使用过 Eclipse 生成器,但由于缺乏更好的解决方案,也许这种方法可以解决您的问题,因为它使您可以更好地控制 Eclipse 项目。

When I use Eclipse with CMake, I create the Eclipse project manually (with the New Project wizard) and for CMake I use the standard makefile generator. It requires a little extra setup: you need to set the build directory in the project properties if you're doing an out-of-source build, and I usually set the build command to make VERBOSE=1.

I'm not sure since I haven't used the Eclipse generator(s), but for the lack of a better solution, perhaps this method would solve your issue, since it gives you more control over the Eclipse project.

梦醒时光2024-12-05 11:36:43

不,如果你不告诉 ide 要编译什么,IDE 如何知道要编译什么?如果您不想在项目文件中包含该项目,则不要添加它。

只需自行编译外部库(使用“cmake externals/foo”),然后将库添加到项目的 CMakeLists.txt 中

target_link_libraries(your_project externals/foo/bin/foo.lib)

No, how should the ide know what to compile if you don't tell it what to compile? If you don't want to have the project in you project file, just don't add it.

Just compile the external lib by itself (use "cmake externals/foo") and then add the libraries in your project's CMakeLists.txt with

target_link_libraries(your_project externals/foo/bin/foo.lib)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文