将一个cmake项目嵌入另一个? [英] Embedding one cmake project inside of another?

查看:1392
本文介绍了将一个cmake项目嵌入另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目,两个都使用CMake。现在我想将其中一个项目包含在另一个库中,同时仍然保持将其编译为独立项目的能力。

I have two projects, both of which use CMake. Now I want to include one of the projects as a library inside the other, while still maintaining the ability to compile them as standalone projects.

到目前为止,我所做的是:使用版本控制系统在父项目的子目录中克隆子项目的副本。我使用add_subdirectory将子项目的CMakeLists.txt包含在父项目中。我通过重命名子项目中的一些目标,在目标之间固定名称冲突。

What I have done so far is: Use the version control system to clone a copy of the child project in a subdir of the parent project. I've used the "add_subdirectory" to include the CMakeLists.txt of the child project into the parent project. And I have fixed name collisions between targets by renaming some of the targets in the child project.

但是,我遇到的一个问题是,各种配置测试子项目似乎没有运行。例如,子项目使用FindThreads模块来确定什么同步原语可用。父项目不知道线程问题,因此没有任何与此相关的测试。类似地,子项目对头部有各种测试,而父项目不需要。这些测试都没有运行,并且这些测试定义的符号未添加到CMakeCache.txt文件中。

However, an issue that I am running into is that the various configuration tests in the child project don't seem to be running. For example, the child project uses the FindThreads module to determine what synchronization primitives are available. The parent project is unaware of threading issues and therefore does not have any tests related to this. Similarly, the child project has various tests for headers and such that are not needed by the parent project. None of these tests appear to be running, and the symbols defined by these tests aren't being added to the CMakeCache.txt file.

我真的不想必须将所有子项目的测试(主要处理与父项无关的平台特定问题)放入父项目的CMakeLists.txt中。

I really don't want to have to hoist all of the child project's tests (which mostly deal with platform-specific issues that are not relevant to the parent) into the parent project's CMakeLists.txt.

推荐答案

CMake 2.8新增了一个外部项目模块,它允许您创建自定义目标来驱动另一个CMake项目的构建。关于这一点的文档有点弱,但它看起来像它可以做你想要的。

CMake 2.8 added a new External Project module, which lets you create a custom target to drive the build of another CMake project. The documentation on this is kind of weak, but it looks like it might do what you want.

我想这个想法是从父项目调用ExternalProject_Add,将它指向子项目的源目录(甚至可以检查子项目的SVN或CVS为你,很好!)。

I think the idea would be to call ExternalProject_Add from your parent project, pointing it to the source directory of the child project (you can even have it check the child project out of SVN or CVS for you, nice!).

这篇关于将一个cmake项目嵌入另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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