当前位置:网站首页>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目标。
边栏推荐
猜你喜欢
兰空图床苹果快捷指令
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
Summary of PHP pseudo protocol of cisp-pte
How to uninstall MySQL cleanly
Jarvis OJ shell traffic analysis
[729. My schedule I]
Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
【性能测试】jmeter+Grafana+influxdb部署实战
Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
Deep learning plus
随机推荐
What else do you not know about new map()
[Jianzhi offer] 63 Maximum profit of stock
Data verification before and after JSON to map -- custom UDF
WSL2.0安装
Do sqlserver have any requirements for database performance when doing CDC
干货!半监督预训练对话模型 SPACE
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
Games101 notes (III)
Games101 notes (I)
【剑指 Offer】63. 股票的最大利润
[61dctf]fm
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
dried food! Semi supervised pre training dialogue model space
[Web attack and Defense] WAF detection technology map
Deep dive kotlin synergy (XXI): flow life cycle function
Embedded -arm (bare board development) -2
Cs231n notes (bottom) - applicable to 0 Foundation
网站页面禁止复制内容 JS代码
【剑指 Offer】61. 扑克牌中的顺子