强制在CMake中针对特定目标执行串行执行 [英] Force serial execution for specific targets in CMake

查看:244
本文介绍了强制在CMake中针对特定目标执行串行执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的CMake项目中,我有几个目标,它们仅运行一组特定的单元测试(例如, runTestsForA runTestsForB runTestsForC )。
我还有一个目标 tests ,它取决于所有这些单元测试目标,因此我可以用一个命令运行它们。



我正在使用CLion是我的IDE,它默认尝试使用并行make构建(我想要并且也在Continuous Integration服务器上使用)。
但是,看起来这些测试现在也正在并行运行,并且还没有为此进行某些测试(它们使用本地环回对套接字进行了一些魔术处理),这导致它们失败。 p>

这就是为什么我要强制对 tests 目标的某些/所有依赖项执行串行执行的原因。
不幸的是,当我搜索有关如何执行此操作的信息时,CMake文档没有帮助我。
这使我想到了一个问题:这是否可能?如果可行,怎么办?

解决方案

您可以使用CTest工具来代替手动 tests 目标声明。使用 add_test 命令创建测试目标,然后CMake将自动创建将运行所有测试的 tests 目标:

  enable_testing()
add_test(NAME TestsForA COMMAND< command>)
add_test(NAME TestsForB COMMAND< command> ;)
set_tests_properties(TestsForA TestsForB PROPERTIES RUN_SERIAL TRUE)

之后,您可以运行进行测试 ctest 。测试将被序列化。



更多信息,请参见:




In my CMake project I have several targets which simply run a certain set of unit tests (for example, runTestsForA, runTestsForB and runTestsForC). I also have a target, tests, that depends on all of these unit test targets, so I can run them with a single command.

I'm using CLion is my IDE, which tries to use parallel make builds by default (which I want and am also doing on the Continuous Integration server). However, it looks like the tests are running in parallel too now and some tests are not made for this (they use a local loopback to do some magic with sockets), which causes them to fail.. sometimes.

That is why I would like to force serial execution for some/all of the dependencies of my tests target. Unfortunately the CMake documentation did not help me, when I was searching information on how to do this. Which brings me to my questions: is this at all possible and how can it be done if it is?

解决方案

Instead of manual tests target declaration you can use CTest tool. Use add_test command to create test targets, then CMake will automatically create tests target that will run all tests:

enable_testing()
add_test(NAME TestsForA COMMAND <command>)
add_test(NAME TestsForB COMMAND <command>)
set_tests_properties(TestsForA TestsForB  PROPERTIES RUN_SERIAL TRUE)

After that you can run make tests or ctest in your build tree. The tests will be serialized.

More information can be found at:

这篇关于强制在CMake中针对特定目标执行串行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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