当前位置:网站首页>CMake教程Step4(安装和测试)
CMake教程Step4(安装和测试)
2022-07-05 16:36:00 【开始沸腾了】
CMake官方文档
参考官方cmake3.24教程翻译
https://cmake.org/cmake/help/v3.24/guide/tutorial/index.html
https://gitlab.kitware.com/cmake/cmake/-/tree/master/Help/guide/tutorial
step4
https://cmake.org/cmake/help/v3.24/guide/tutorial/Installing%20and%20Testing.html
我的仓库 :
https://github.com/FRBoiling/cmake-tutorial.git
现在我们可以开始向我们的项目添加安装规则和测试支持
安装规则
安装规则相当简单:
对于MathFunctions库,我们想要安装库和头文件,
对于应用程序,我们要安装可执行文件和配置的头文件。
因此,我们在MathFunctions/CMakeLists.txt的末尾添加:
install(TARGETS MathFunctions DESTINATION lib)
install(FILES math_functions.h DESTINATION include)
在顶层的Step4/CMakeLists.txt文件的末尾添加:
install(TARGETS Tutorial DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/tutorial_config.h"
DESTINATION include
)
这就是创建本教程的基本本地安装所需的全部内容。
现在运行cmake可执行文件或cmake-gui来配置项目,然后使用您选择的构建工具构建它。
然后在命令行中使用cmake命令(3.15引入,旧版本的cmake必须使用make install)的install选项来运行安装步骤。对于多配置工具,不要忘记使用——config参数来指定配置。如果使用IDE,只需构建INSTALL目标。这一步将安装适当的头文件、库和可执行文件。例如:
cmake --install .

如上,安装时候默认路径权限不够。可以提升操作权限,或者指定权限合适的目录去安装。
CMake变量CMAKE_INSTALL_PREFIX用于确定将安装文件的根目录。
如果使用cmake --install命令,可以通过–prefix参数覆盖安装前缀。例如:
cmake --install . --prefix "../Step4_Installdir"


进入到安装目录,验证安装的教程是否运行。
测试支持
接下来,让我们测试应用程序。在顶级CMakeLists.txt文件的末尾,我们可以启用测试,然后添加一些基本测试,以验证应用程序是否正常工作。
enable_testing()
# does the application run
add_test(NAME Runs COMMAND Tutorial 25)
# does the usage message work?
add_test(NAME Usage COMMAND Tutorial)
set_tests_properties(Usage
PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number"
)
# define a function to simplify adding tests
function(do_test target arg result)
add_test(NAME Comp${arg} COMMAND ${target} ${arg})
set_tests_properties(Comp${arg}
PROPERTIES PASS_REGULAR_EXPRESSION ${result}
)
endfunction()
# do a bunch of result based tests
do_test(Tutorial 4 "4 is 2")
do_test(Tutorial 9 "9 is 3")
do_test(Tutorial 5 "5 is 2.236")
do_test(Tutorial 7 "7 is 2.645")
do_test(Tutorial 25 "25 is 5")
do_test(Tutorial -25 "-25 is (-nan|nan|0)")
do_test(Tutorial 0.0001 "0.0001 is 0.01")
第一个测试只是验证应用程序是否运行,是否存在段错误或崩溃,返回值是否为零。这是CTest测试的基本形式。
第二个测试,测试使用PASS_REGULAR_EXPRESSION测试属性来验证测试的输出是否包含某些字符串。在这种情况下,当提供的参数数量不正确时,验证是否打印了用法消息。
然后,我们有一个名为do_test的函数,它运行应用程序并验证给定输入的计算平方根是否正确。
do_test的每次调用,都会将另一个测试添加到项目中,该测试带有名称、输入和基于传递的参数的预期结果。
重新构建应用程序,然后进入Step4_build目录 ,运行ctest可执行文件:
ctest -N和ctest -VV。



对于多配置生成器(例如Visual Studio),配置类型必须使用-C 标志指定。
例如,要在Debug模式下运行测试,请使用二进制目录(而不是Debug子目录!)中的ctest -C Debug -VV。
Release模式将从相同的位置执行使用-C Release。或者,从IDE构建RUN_TESTS目标。
边栏推荐
- Deep dive kotlin synergy (XXI): flow life cycle function
- 【beanshell】数据写入本地多种方法
- 【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
- Embedded-c Language-2
- [Web attack and Defense] WAF detection technology map
- 【性能测试】jmeter+Grafana+influxdb部署实战
- Embedded-c Language-5
- Deep learning plus
- Writing method of twig array merging
- The first lesson of EasyX learning
猜你喜欢

激动人心!2022开放原子全球开源峰会报名火热开启!

Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)

Hiengine: comparable to the local cloud native memory database engine

The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%

NPM installation

【性能测试】jmeter+Grafana+influxdb部署实战

Embedded-c Language-2

Copy mode DMA

Jarvis OJ 远程登录协议

浏览器渲染原理以及重排与重绘
随机推荐
干货!半监督预训练对话模型 SPACE
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
PHP strict mode
If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
Raspberry pie 4B installation pytorch1.11
File operation --i/o
How does the outer disk futures platform distinguish formal security?
It is forbidden to copy content JS code on the website page
ECU introduction
Can you help me see what the problem is? [ERROR] Could not execute SQL stateme
Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
thinkphp3.2.3
【剑指 Offer】63. 股票的最大利润
PHP talent recruitment system development source code recruitment website source code secondary development
Games101 notes (II)
Hiengine: comparable to the local cloud native memory database engine
7.Scala类
【性能测试】jmeter+Grafana+influxdb部署实战