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

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

问题描述

我正在 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.

所以我正在寻找一种方法来明确指定此依赖项.

So I'm looking for a way to explicitly specify this dependency.

推荐答案

可以说CMake 中的错误(之前在此处跟踪) 这不是开箱即用的.解决方法是执行以下操作:

It is arguably a bug in CMake (previously 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 test 不构建测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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