c++ - CMake : several projects using custom target to make test

标签 c++ git cmake git-submodules

假设我有一个库 ProjectA,我在我的 CMakefile 中定义了一个自定义目标 build-tests 来构建我的测试,这样我就可以做 make test 之后。 (参见 CMake & CTest : make test doesn't build tests)。

然后,我有第二个库 ProjectB,它依赖于 ProjectA。我使用 git submodule 这样我就可以在 ProjectB 的 CMakefile 中执行 add_subdirectory(ProjectA)。问题是,我想做同样的事情:定义一个自定义目标 build-tests 来构建 ProjectB 的测试,但我不能,因为它已经在项目A...

我的问题类似于How to handle a transitive dependency conflict using Git submodules and CMake?CMake and using git-submodule for dependence projects但他们可以定义一个目标来避免这种情况,而我希望能够在 ProjectAProjectB 中进行 make build-tests

那么,有没有办法在本地为 cmake 项目定义自定义目标?还是有一种聪明的方法来做我想做的事? (这看起来很自然)

最佳答案

So, is there a way to define a custom target locally to a cmake project for example ? or is there a clever way to do what I would like to do ? (which seems quite natural)

因为您正在使用自定义目标,可能是 ALLOW_DUPLICATE_CUSTOM_TARGETS可以胜任这项工作。
文档确实非常清楚:

Allow duplicate custom targets to be created.

如果你走得更远一点,你会发现:

The property allows multiple add_custom_target command calls in different directories to specify the same target name.

不幸的是它也有一些限制:

[...] setting this property will cause non-Makefile generators to produce an error and refuse to generate the project.

仔细阅读文档(参见上面的链接)以了解它是否适​​合您的目的。

关于c++ - CMake : several projects using custom target to make test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45065290/

相关文章:

c++ - 我的输出文件未从输入文件中读取空格

git - 是否可以在 gitlab-ci 中将另一个分支构建到另一个目录?

c++ - WxWidgets:简单的数学公式给出错误的结果?

C++元编程递归步数限制

c++ - 与 DEBUG 宏混淆

git - Jenkins的Gradle发布插件未推送发布版本

git - 克隆一个包含所有子模块的 git repo

c++ - 向 CMake 引入新的编译器

c++ - 设置诊断 :caret from CMakeLists. txt

c++ - message.pb.h 文件中的 Protobuf : Cannot open include file common. h