一旦我们设置了交叉编译环境,我们可以使用CMake的测试功能来验证我们的程序。CMake提供了add_test()命令,允许我们定义测试用例。 // 示例代码add_executable(my_testtest.cpp)add_test(NAMEMyTestCOMMANDmy_test) 这段代码首先创建一个名为my_test的可执行文件,然后定义一个名为MyTest的测试,该测试将执行my_test。
set_tests_properties (test_${arg1}_${arg2} PROPERTIES PASS_REGULAR_EXPRESSION ${result}) endmacro (do_test) # 使用该宏进行一系列的数据测试 do_test (35 2 "37") do_test (5 52 "7") do_test (2 3 "5") 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 关于CTest 的更详细的用法可...
Passed 0.00 sec 100% tests passed, 0 tests failed out of 4 Total Test time (real) = 0.01 sec 如果要测试更多的输入数据,像上面那样一个个写测试用例未免太繁琐。这时可以通过编写宏来实现: # 定义一个宏,用来简化测试工作 macro (do_test arg1 arg2 result) add_test (test_${arg1}_${arg2} ...
do_test (10 5 "is 100000") do_test (2 10 "is 1024") enable_testing:用于启动测试。 add_test:用于添加测试,第一个参数为测试名,第二个参数为可执行程序,剩下的为可执行程序的参数。 set_tests_properties:测试的提示信息。 macro:宏,用于编写一个重复性操作来简化测试用例的编写。 do_test:编写的测...
├── testFunc.c└── testFunc.h 这里需要修改CMakeLists.txt,在add_executable的参数里把testFunc.c加进来,可以类推,如果在同一目录下有多个源文件,那么只要在add_executable里把所有源文件都添加进去就可以了。 三、 在不同目录下有多个源文件 结构:├── CMakeLists.txt├── main.c├── test_...
其中,MY_VARIABLE表示判断的条件,STREQUAL表示字符串相等。如果条件成立,则执行do something部分的代码。 endif endif命令用于结束if语句块。其实,在CMake中,所有的控制流语句都需要以endif命令结束。举个例子,假设我们需要判断变量MY_VARIABLE是否等于hello world,如果成立,则打印一条消息,否则打印另一条消息,我们可以使...
我们将保持main.cpp、sum_integers.cpp和sum_integers.hpp与之前的配方不变,但将更新test.cpp: 代码语言:javascript 复制 #include "sum_integers.hpp" // this tells catch to provide a main() // only do this in one cpp file #define CATCH_CONFIG_MAIN ...
CMake 也可以指定安装规则,以及添加测试。这两个功能分别可以通过在产生 Makefile 后使用make install和make test来执行。在以前的 GNU Makefile 里,你可能需要为此编写install和test两个伪目标和相应的规则,但在 CMake 里,这样的工作同样只需要简单的调用几条命令。
Dependent on good CMakeListsMany libraries do not have CMakeLists that work well for subprojects. Luckily this is slowly changing, however, until then, some manual configuration may be required (see the snippetsbelowfor examples). For best practices on preparing projects for CPM, see thewiki. ...
CMake Error at /arm/tools/gnu/cmake/3.14.3/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake:60 (message): The C compiler is not able to compile a simple test program. Can I skip cmake compiler tests or avoid “error: unrecognized option '-rdynamic'” ...