当前位置:网站首页>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 .
边栏推荐
- 云主机oracle异常恢复----惜分飞
- Cartoon: how to multiply large integers? (next)
- Disorganized series
- Please tell me why some tables can find data by writing SQL, but they can't be found in the data map, and the table structure can't be found
- Accuracy of BigDecimal Division
- Tips for extracting JSON fields from MySQL
- mybash
- 论文阅读_医疗NLP模型_ EMBERT
- 力扣解法汇总1200-最小绝对差
- Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
猜你喜欢
Server configuration jupyter environment
Mongodb (quick start) (I)
求解为啥all(())是True, 而any(())是FALSE?
十个顶级自动化和编排工具
ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée
To solve the problem of "double click PDF file, pop up", please install Evernote program
mongodb(快速上手)(一)
Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
Knowledge points of MySQL (7)
论文阅读_医疗NLP模型_ EMBERT
随机推荐
Knowledge points of MySQL (7)
网络威胁分析师应该具备的十种能力
Winedt common shortcut key modify shortcut key latex compile button
较文心损失一点点性能提升很多
The five most difficult programming languages in the world
How to save the trained neural network model (pytorch version)
How MySQL uses JSON_ Extract() takes JSON value
世界上最难的5种编程语言
Domain name resolution, reverse domain name resolution nbtstat
解读:如何应对物联网目前面临的安全问题?
证券网上开户安全吗?证券融资利率一般是多少?
c#图文混合,以二进制方式写入数据库
Tips for extracting JSON fields from MySQL
Oracle缩表空间的完整解决实例
使用QT设计师界面类创建2个界面,通过按键从界面1切换到界面2
Tita 绩效宝:如何为年中考核做准备?
Disabling and enabling inspections pycharm
flask接口响应中的中文乱码(unicode)处理
mysql5.6解析JSON字符串方式(支持复杂的嵌套格式)
Troubleshooting - about clip not found Visual Studio