当前位置:网站首页>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 .
边栏推荐
- MySQL之知识点(六)
- Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
- Use QT designer interface class to create two interfaces, and switch from interface 1 to interface 2 by pressing the key
- Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
- 服务器配置 jupyter环境
- 解读:如何应对物联网目前面临的安全问题?
- Read the history of it development in one breath
- Cmake tutorial Step3 (requirements for adding libraries)
- Matery主题自定义(一)黑夜模式
- Tita 绩效宝:如何为年中考核做准备?
猜你喜欢

哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?

PMP认证需具备哪些条件啊?费用多少啊?

Winedt common shortcut key modify shortcut key latex compile button

Design of electronic clock based on 51 single chip microcomputer

Check the WiFi password connected to your computer

Seven Devops practices to improve application performance

mongodb(快速上手)(一)
Learn about MySQL transaction isolation level

2022新版PMP考试有哪些变化?

北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
随机推荐
leetcode每日一练:旋转数组
What are the precautions for MySQL group by
Webapp development - Google official tutorial
Size_t 是无符号的
基于YOLOv3的口罩佩戴检测
Tita performance treasure: how to prepare for the mid year examination?
2022新版PMP考试有哪些变化?
EPM相关
Winedt common shortcut key modify shortcut key latex compile button
Redis+caffeine two-level cache enables smooth access speed
Why is all (()) true and any (()) false?
云主机oracle异常恢复----惜分飞
Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
Tita 绩效宝:如何为年中考核做准备?
Server configuration jupyter environment
Disabling and enabling inspections pycharm
mongodb(快速上手)(一)
Database design in multi tenant mode
Abnormal recovery of virtual machine Oracle -- Xi Fenfei
2022 information system management engineer examination outline