CMake& CTest:make测试不构建测试 [英] CMake & CTest : make test doesn't build tests

查看:435
本文介绍了CMake& CTest:make测试不构建测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CMake尝试CTest,以便使用 make test 目标自动运行我的一些测试。问题是CMake不理解我愿意运行的测试必须建立,因为它是项目的一部分。

I'm trying CTest in CMake in order to automatically run some of my tests using make test target. The problem is CMake does not "understand" that the test I'm willing to run has to be built since it is part of the project.

所以我看

推荐答案

这是可以争辩的 a CMake中的错误(错误现已追踪这里),这不是开箱即用。解决方法是执行以下操作:

It is arguably a bug in CMake (bug now tracked here) that this doesn't work out of the box. A workaround is to do the following:

add_test(TestName ExeName)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
                  DEPENDS ExeName)

然后您可以运行 make check ,它将编译并运行测试。如果你有几个测试,那么你必须在上面一行中使用 DEPENDS exe1 exe2 exe3 ...

Then you can run make check and it will compile and run the test. If you have several tests, then you would have to use DEPENDS exe1 exe2 exe3 ... in the above line.

这篇关于CMake& CTest:make测试不构建测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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