cmake/ctest:是否可以使用构建目标的创建作为测试?
我有一个程序,它读取文件格式的描述(好奇的 ISO 10303-11)并从中生成 c++。生成的代码被编译到库中,并且该库与各种可执行文件链接以读取/写入该文件格式。
我已设置 CMake 来构建生成器程序并为配置时指定的任何文件格式生成库。
现在,我想添加测试。这些测试与构建过程中已完成的步骤相同 - 我必须在 CTest 脚本中重做这些步骤,还是有办法告诉 ctest 构建目标并捕获任何错误消息?
I have a program which reads a description of a file format (ISO 10303-11 for the curious) and generates c++ from it. The generated code is compiled into a library, and the library is linked with various executables to read/write that file format.
I have CMake set up to build the generator program and generate libraries for whichever file formats are specified at configuration time.
Now, I want to add tests. These tests are identical to steps that are already done in the build process - must I redo these steps in a CTest script, or is there a way to tell ctest to build a target and capture any error messages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是足够新的 ctest 版本(最新的官方版本是 2.8.6),那么您可以使用 add_test 的 NAME/COMMAND 签名,结合 cmake --build 命令行选项,在您的构建树。
例如,假设有一个名为“tgt1”的自定义目标(或库或可执行目标),以下内容应该可以工作:
这可以跨平台工作,在任何地方都使用相同的语法。它甚至可以与多配置生成器一起使用,例如 Visual Studio 和 Xcode。
If you are using a recent enough version of ctest (most recent official release is 2.8.6) then you can use the NAME/COMMAND signature of add_test, in conjunction with the cmake --build command line option, to build specific targets in your build tree.
For example, the following should work, assuming a custom target (or library or executable target) named "tgt1":
This works cross-platform with the same syntax everywhere. It even works with multi-configuration generators, like Visual Studio and Xcode.
您是否尝试过在
CMakeLists.txt
文件中输入enable_testing()
,然后调用add_test()
来创建测试目标?我认为如果您遵循 CMake 文档,您可以在一个统一的构建脚本中完成所有操作。Have you tried saying
enable_testing()
in yourCMakeLists.txt
file, then callingadd_test()
to make a test target? I think you can do everything in one consolidated build script if you follow the CMake documentation.