如何使用Boost.Test在CMake的基于项目? [英] How can I use Boost.Test in a CMake based project?

查看:586
本文介绍了如何使用Boost.Test在CMake的基于项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用的CMake作为其构建系统,我想它来执行我的Boost.Test测试用例。

我怎样才能做到这一点?在Boost.Build,如下我能做到这一点:

 导入测试;使用项目/ my_lib:../src;单元测试my_test
          :my_test.cpp
            / my_lib
          boost_unit_test_framework
        ;LIB boost_unit_test_framework;


解决方案

CMake的本身只是一个构建系统; CTEST是与CMake的整合只是一个测试运行。无论是单元测试框架;这项工作可以通过Boost.Test或googletest完成。

要在CMake的项目中使用基于Boost.Test单元测试程序,你首先必须建立的CMake并链接单元测试二进制文件,使用 add_executable target_link_libraries 的CMakeLists.txt 脚本。然后,您可以将单元测试二进制文件添加到为CTEST测试列表与 enable_testing 运行和 add_test

如果你想获得真正看中的,你可以看看通过CMake的文档,如何你要通过所有源文件的CMake搜索自动查找和创建单元测试,但首要的事情...

My project uses CMake as its build system, and I want it to execute my Boost.Test test cases.

How can I achieve that? In Boost.Build, I could do it as follows:

import testing ;

use-project /my_lib : ../src ;

unit-test my_test
          : my_test.cpp
            /my_lib
          boost_unit_test_framework
        ;

lib boost_unit_test_framework ;

解决方案

CMake itself is just a build system; CTest is a just test runner that is integrated with CMake. Neither is a unit test framework; that job can be done by Boost.Test or googletest.

To use a Boost.Test-based unit test program in a CMake project, you'd first have CMake build and link your unit test binary, using add_executable and target_link_libraries in your CMakeLists.txt script. Then, you can add the unit test binary to the list of tests for CTest to run with enable_testing and add_test.

If you want to get really fancy, you can look through the CMake documentation for how to have CMake search through all your source files to find and build unit tests automatically, but first things first...

这篇关于如何使用Boost.Test在CMake的基于项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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