CMake 和 CTest:如何使目标“每晚”实际构建测试

发布于 2024-09-10 14:42:17 字数 636 浏览 3 评论 0原文

这是一个众所周知的问题,执行 make "test" 不会构建所讨论的测试 这里。正如所建议的,这个问题可以通过人工目标“检查”来部分解决。我想知道当我调用“make Nightly”时如何强制构建测试。

到目前为止我所做的:

  add_custom_target(buildtests)
  add_custom_target(check COMMAND "ctest")
  add_dependencies(check buildtests)
  add_dependencies(Nightly buildtests)

  add_dependencies(buildtests Test1)
  ...
  add_dependencies(buildtests TestN)

现在“make check”构建并运行测试,但“make Nightly”

  • 构建测试
  • 将存储库更新为 CTEST_NIGHTLY_START_TIME
  • 构建所有其他目标
  • 运行(现已过时)测试

It's a well known problem that executing make "test" doesn't build the tests as discussed here. As suggested, the problem can be partly solved with the artificial target "check". I want to know how I can force building of tests when i call "make Nightly".

What I've done so far:

  add_custom_target(buildtests)
  add_custom_target(check COMMAND "ctest")
  add_dependencies(check buildtests)
  add_dependencies(Nightly buildtests)

  add_dependencies(buildtests Test1)
  ...
  add_dependencies(buildtests TestN)

Now "make check" builds an runs the tests, but "make Nightly"

  • builds the tests
  • updates the repo to CTEST_NIGHTLY_START_TIME
  • builds all other targets
  • runs the (now outdated) tests

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏大泽ㄣ 2024-09-17 14:42:17

你是对的,这实际上是我自己的调用错误:

add_subdirectory(test EXCLUDE_FROM_ALL)

解决方案是将其更改为

if(LEAVE_TEST_IN_ALL_TARGET) 
  add_subdirectory(test) 
else() 
  add_subdirectory(test EXCLUDE_FROM_ALL) 
endif() 

然后调用

cmake ${SRC_DIR} -DLEAVE_TEST_IN_ALL_TARGET=ON make Nightly

You're right, it was actually my own fault for calling:

add_subdirectory(test EXCLUDE_FROM_ALL)

The solution was to change it to

if(LEAVE_TEST_IN_ALL_TARGET) 
  add_subdirectory(test) 
else() 
  add_subdirectory(test EXCLUDE_FROM_ALL) 
endif() 

and then call

cmake ${SRC_DIR} -DLEAVE_TEST_IN_ALL_TARGET=ON make Nightly
枯叶蝶 2024-09-17 14:42:17

如果您查看输出,

cmake --help-command add_custom_target

它提到了 ALL 参数,“如果指定了 ALL 选项,则表明应将此目标添加到默认构建目标,以便每次都会运行它”。您需要将此参数添加到自定义目标中,并且 Nightly 目标运行 make 来构建默认构建目标中的所有内容。因此,应该执行以下操作,

add_custom_target(buildtests)

您的另一个选择是编写自定义 CTest 脚本,它可以让您对项目的构建和测试进行更细粒度的控制。

If you look at the output of,

cmake --help-command add_custom_target

It mentions the ALL argument, "If the ALL option is specified it indicates that this target should be added to the default build target so that it will be run every time". You would need to add this argument to your custom target, and the Nightly target runs a make to build everything in the default build target. So the following should do it,

add_custom_target(buildtests)

Your other option would be to write a custom CTest script, which gives you much finer grained control of the build and testing of your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文