当前位置:网站首页>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目标。
边栏推荐
- High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
- Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- Embedded-c Language-5
- Embedded-c Language-2
- dried food! Semi supervised pre training dialogue model space
- 调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
- C# TCP如何设置心跳数据包,才显得优雅呢?
- Cs231n notes (bottom) - applicable to 0 Foundation
- The third lesson of EasyX learning
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
猜你喜欢

Iphone14 with pill screen may trigger a rush for Chinese consumers

Jarvis OJ Flag

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

ECU introduction

采用药丸屏的iPhone14或引发中国消费者的热烈抢购

机器学习编译第2讲:张量程序抽象

If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats

腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权

飞桨EasyDL实操范例:工业零件划痕自动识别

Benji Banas membership pass holders' second quarter reward activities update list
随机推荐
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
关于new Map( )还有哪些是你不知道的
Google Earth engine (GEE) -- a brief introduction to kernel kernel functions and gray level co-occurrence matrix
Etcd 构建高可用Etcd集群
Games101 notes (I)
Embedded UC (UNIX System Advanced Programming) -3
Jarvis OJ simple network management protocol
Embedded-c Language-3
Get ready for the pre-season card game MotoGP ignition champions!
张平安:加快云上数字创新,共建产业智慧生态
Jarvis OJ Webshell分析
How to install MySQL
精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
Sentinel-流量防卫兵
Practical example of propeller easydl: automatic scratch recognition of industrial parts
[Jianzhi offer] 66 Build product array
Yarn common commands
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
【性能测试】全链路压测