当前位置:网站首页>Cmake tutorial Step4 (installation and testing)
Cmake tutorial Step4 (installation and testing)
2022-07-05 17:45:00 【It's beginning to boil】
CMake Official documents
Refer to the official cmake3.24 Course translation
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
My warehouse :
https://github.com/FRBoiling/cmake-tutorial.git
Now we can start adding installation rules and test support to our project
Installation rules
The installation rules are quite simple :
about MathFunctions library , We want to install libraries and header files ,
For applications , We need to install the executable file and the configured header file .
therefore , We are MathFunctions/CMakeLists.txt Added at the end of :
install(TARGETS MathFunctions DESTINATION lib)
install(FILES math_functions.h DESTINATION include)
On the top floor Step4/CMakeLists.txt Add... At the end of the file :
install(TARGETS Tutorial DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/tutorial_config.h"
DESTINATION include
)
This is all you need to create a basic local installation for this tutorial .
Now run cmake Executable or cmake-gui To configure the project , Then build it using the build tool of your choice .
Then use the cmake command (3.15 introduce , The old version of cmake You have to use make install) Of install Option to run the installation steps . For multi configuration tools , Don't forget to use ——config Parameters to specify the configuration . If you use IDE, Just build INSTALL The goal is . This step will install the appropriate header file 、 Libraries and executables . for example :
cmake --install .

Above , The default path permission is insufficient during installation . Operation permission can be increased , Or specify a directory with appropriate permissions to install .
CMake Variable CMAKE_INSTALL_PREFIX Used to determine the root directory of the files to be installed .
If you use cmake --install command , Can pass –prefix Parameters override the installation prefix . for example :
cmake --install . --prefix "../Step4_Installdir"


Go to the installation directory , Verify that the installed tutorial is running .
Test support
Next , Let's test the application . At the top CMakeLists.txt End of file , We can enable testing , Then add some basic tests , To verify that the application is working .
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")
The first test is just to verify whether the application is running , Whether there are segment errors or crashes , Whether the return value is zero . This is a CTest The basic form of testing .
The second test , Test use PASS_REGULAR_EXPRESSION Test properties to verify that the output of the test contains some strings . under these circumstances , When the number of parameters provided is incorrect , Verify that the usage message is printed .
then , We have one called do_test Function of , It runs the application and verifies that the calculated square root of a given input is correct .
do_test Every call to , Will add another test to the project , The test has a name 、 Input and expected results based on passed parameters .
Rebuild the application , Then enter Step4_build Catalog , function ctest Executable file :
ctest -N and ctest -VV.



For multiple configuration generators ( for example Visual Studio), Configuration type must use -C Mark designation .
for example , To be in Debug Run the test in mode , Please use binary directory ( instead of Debug subdirectories !) Medium ctest -C Debug -VV.
Release The mode will be used from the same location -C Release. perhaps , from IDE structure RUN_TESTS The goal is .
边栏推荐
- Independent development is a way out for programmers
- 力扣解法汇总1200-最小绝对差
- ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée
- This 17-year-old hacker genius cracked the first generation iPhone!
- Oracle缩表空间的完整解决实例
- Cmake tutorial step5 (add system self-test)
- Flask solves the problem of CORS err
- Knowledge points of MySQL (6)
- 企业数字化发展中的六个安全陋习,每一个都很危险!
- 如何修改mysql字段为自增长字段
猜你喜欢
Redis+caffeine two-level cache enables smooth access speed

Anaconda中配置PyTorch环境——win10系统(小白包会)

Winedt common shortcut key modify shortcut key latex compile button

Thesis reading_ Chinese NLP_ LTP

Oracle recovery tools -- Oracle database recovery tool

服务器配置 jupyter环境

Check the WiFi password connected to your computer

ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée

Thesis reading_ Medical NLP model_ EMBERT

解决“双击pdf文件,弹出”请安装evernote程序
随机推荐
PMP认证需具备哪些条件啊?费用多少啊?
较文心损失一点点性能提升很多
Cmake tutorial step6 (add custom commands and generate files)
外盘黄金哪个平台正规安全,怎么辨别?
证券网上开户安全吗?证券融资利率一般是多少?
Tips for extracting JSON fields from MySQL
神经网络自我认知模型
Tita performance treasure: how to prepare for the mid year examination?
Disabling and enabling inspections pycharm
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
一文读懂简单查询代价估算
C # realizes crystal report binding data and printing 3-qr code barcode
提高應用程序性能的7個DevOps實踐
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
Redis+caffeine two-level cache enables smooth access speed
Matlab reference
Why is February 28 in the Gregorian calendar
Webapp development - Google official tutorial
Winedt common shortcut key modify shortcut key latex compile button
统计php程序运行时间及设置PHP最长运行时间