1.前言

为之前的项目添加安装规则install rules和测试支持testing support

2.安装规则installing rules

安装规则是相当直接的了。对于我们设置的MathFunctions库和头文件,通过在MathFunctions的CMakeLists.txt中添加如下两行代码:
install (TARGETS MathFunctions DESTINATION bin)
install (FILES MathFunctions.h DESTINATION include)

然后,在顶层CMakeLists.txt文件添加如下代码安装可执行程序,并配置头文件:

# add the install targets
install (TARGETS Tutorial DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h" DESTINATION include)

这就是全部了。接下来就能够组建tutorial,然后利用‘make’进行安装(也可以在IDE中组建INSTALL目标)。
这样就会安装盛和的头文件、库文件和可执行文件。

注意:CMake变量‘CMake_INSTALL_PREFIX’是决定将文件安装在哪个目录下。

3.测试支持Testing Support

测试也是一个非常直接的步骤。
在顶层CMakeList.txt文件最后,我们可以添加大量的基础测试代码,用来验证应用程序是否正常工作。
include(CTest)# does the application run
add_test (TutorialRuns Tutorial 25)# does it sqrt of 25
add_test (TutorialComp25 Tutorial 25)
set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")# does it handle negative numbers
add_test (TutorialNegative Tutorial -25)
set_tests_properties (TutorialNegative PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0")# does it handle small numbers
add_test (TutorialSmall Tutorial 0.0001)
set_tests_properties (TutorialSmall PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01")# does the usage message work?
add_test (TutorialUsage Tutorial)
set_tests_properties (TutorialUsage PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")

组建之后,就可以运行‘ctest’命令行工具运行这些测试代码。

‘PASS_REGULAR_EXPRESSION’测试应用程序输出包含某些字符串。
如果我们希望增加大量的测试代码来测试不同的输入值,我们可以考虑创建一个宏,示例如下:
#define a macro to simplify adding tests, then use it
macro (do_test arg result)add_test (TutorialComp${arg} Tutorial ${arg})set_tests_properties (TutorialComp${arg}PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endmacro (do_test)# do a bunch of result based tests
do_test (25 "25 is 5")
do_test (-25 "-25 is 0")

4.调试与测试

  • ~/CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (Tutorial)# The version number.
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)# configure a header file to pass some of the CMake settings
# to the source code
configure_file ("${PROJECT_SOURCE_DIR}/TutorialConfig.h.in""${PROJECT_BINARY_DIR}/TutorialConfig.h")# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories ("${PROJECT_BINARY_DIR}")# add the MathFunctions library?
if (USE_MYMATH)include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")add_subdirectory (MathFunctions)set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif ()# add the executable
add_executable (Tutorial tutorial.c)
target_link_libraries (Tutorial  ${EXTRA_LIBS})# add the install targets
install (TARGETS Tutorial DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"DESTINATION include)# enable testing
enable_testing ()# does the application run
add_test (TutorialRuns Tutorial 25)# does it sqrt of 25
add_test (TutorialComp25 Tutorial 25)
set_tests_properties (TutorialComp25PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")# does it handle negative numbers
add_test (TutorialNegative Tutorial -25)
set_tests_properties (TutorialNegativePROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0")# does it handle small numbers
add_test (TutorialSmall Tutorial 0.0001)
set_tests_properties (TutorialSmallPROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01")# does the usage message work?
add_test (TutorialUsage Tutorial)
set_tests_properties (TutorialUsagePROPERTIESPASS_REGULAR_EXPRESSION "Usage:.*number")
  • ~/Tutorial.c
// A simple program that computes the square root of a number
#include "TutorialConfig.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>#ifdef USE_MYMATH
#include "MathFunctions.h"
#endifint main(int argc, char* argv[])
{double inputValue = atof(argv[1]); //根据编译器的要求,变量要放在最前面double outputValue = 0;if (argc < 2) {fprintf(stdout, "%s Version %d.%d\n", argv[0], Tutorial_VERSION_MAJOR,Tutorial_VERSION_MINOR);fprintf(stdout, "Usage: %s number\n", argv[0]);return 1;}if (inputValue >= 0) {
#ifdef USE_MYMATHoutputValue = mysqrt(inputValue);
#elseoutputValue = sqrt(inputValue);
#endif}fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);return 0;
}


  • ~/TutorialConfig.h.in

// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
#cmakedefine USE_MYMATH
  • ~/MathFunctions/CMakeLists.txt
add_library(MathFunctions mysqrt.c)install (TARGETS MathFunctions DESTINATION bin)
install (FILES MathFunctions.h DESTINATION include
  • ~/MathFunctions/MathFunctions.h
double mysqrt(double x);
  • ~/MathFunctions/mysqrt.c
#include "MathFunctions.h"
#include <stdio.h>// a hack square root calculation using simple operations
double mysqrt(double x)
{double result; //根据编译器要求,所有变量的定义放在最前面double delta;int i;if (x <= 0) {return 0;}result = x;// do ten iterationsfor (i = 0; i < 10; ++i) {if (result <= 0) {result = 0.1;}delta = x - (result * result);result = result + 0.5 * delta / result;fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);}return result;
}

Step1:CMake进行Configure & Generate

Step2:Visual Studio进行组建ALL_BUILD
Step3:Visual Studio进行安装INSTALL
~/bin;~/include;~/lib文件夹会出现在CMake预定义的目标目录中,例如我的就在C:/ProgramFile

CMake4:安装与测试相关推荐

  1. my SQL下载安装,环境配置,以及密码忘记的解决,以及navicat for mysql下载,安装,测试连接...

    一.下载 在百度上搜索"mysql-5.6.24-winx64下载" 二.安装 选择安装路径,我的路径"C:\Soft\mysql-5.6.24-winx64" ...

  2. http_load安装与测试参数分析

    http_load安装与测试参数分析 http_load以并行复用的方式运行,用以测试 web 服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把客户机搞死. ...

  3. nginx 没有sbin目录_CentOS7下Nginx+ModSecurity配置、安装、测试教程

    " 最近在工作上遇到一点问题,问了大佬.百度,都没有很好地解决:经过大量搜索查阅以及试验,终于将问题解决.于是写下这篇文章以提醒自己,也可供读者参考." 环境:CentOS-7-x ...

  4. AutoBench+Httperf的安装、测试

    首先安装Httperf.主要是Httperf网路上给出的url均无法访问,因此在GitHub上找的源码工程,进行安装. 接下来介绍安装步骤,从Github下载下来的httperf包是zip. unzi ...

  5. 安装并测试nvenc linux sdk

    2019独角兽企业重金招聘Python工程师标准>>> nvidia在cuda之后推出一种官方生成更好视频处理技术nvenc. 网上相关资料很少, 也不知道这个东西到底怎么样,自己测 ...

  6. appium for mac 安装与测试ios说明

    一.安装 安装dmg,可以自己下载appium-1.4.0.dmg或者找rtx我要,文件过大不能添加附件. Appium提供了一个doctor,运行appium-doctor 如果有问题,Fix it ...

  7. Faste R-CNN的安装及测试

    一.拉取源码 下载 fast-rcnn 因下载解压后 caffe-fast-rcnn是空文件夹,故需要单独下 caffe-fast-rcnn-bcd9b4eadc7d8fbc433aeefd564e8 ...

  8. Faster R-CNN的安装及测试(Python版本和Matlab版本)

    rbg的Python版本 一.拉取源码 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 拉取完成后,在/h ...

  9. Eclipse JPBC library安装及测试

    Eclipse JPBC library安装及测试 资源下载路径: 安装配置: JPBC库是一个功能很强大的数学库,用于生成椭圆曲线,双线性等,但网上参考资料很少,重复度极高,该分栏用于安装,JPBC ...

最新文章

  1. 三次握手+四次挥手,一文搞定所有!历史最佳剖析!
  2. 大数据和高并发的解决方案汇总
  3. C# IO操作(五)文件的递归加载
  4. 带滤镜拍照的app_抖音很火的同款拍照(P图)技巧
  5. IO流的应用_Copy文件
  6. diffstat命令
  7. 在php里面找出有用的代码,如何在多个源代码文件中 找到某段代码?
  8. Oracle 导出、导入某用户所有数据(包括表、视图、存储过程...)
  9. 修改设置Tomcat内存
  10. JAVA50道基础编程题
  11. ghostscript windows mac 下安装和 C++ 程序调用
  12. Android OpenCV(六十二):伪彩色增强
  13. matlab图片背景分割,12.4.2 图像分割
  14. BTA分论坛现场直击 | 区块链行业应用有待落地,游戏上链冰火两重天
  15. oracle general ledger,处理 Oracle General Ledger 调整期间
  16. 第二章:EB编译环境Keil的配置(s32k144)
  17. 计算机网络 5 - 链路层
  18. 网络分层架构 ARP baidu.com 访问过程 知识点总结
  19. 概率算法-均匀分布产生正态分布
  20. 一个不错的长微博工具(文图微博)

热门文章

  1. 关于linux系统下文件压缩归档操作命令略提
  2. Xcode7 (Xcode setting ENABLE_BITCODE)
  3. canal中mysql版本错误日志
  4. 出现了奇数次的数字的算法
  5. python list遍历
  6. 一起谈.NET技术,数据库访问的性能问题与瓶颈问题
  7. TACACS +和RADIUS比较
  8. 关于J2EE+DOTNET的一些网站
  9. fzu - 1752 Problem 1752 A^B mod C
  10. 聊一聊Python的变量类型判断type和isinstance