CMake教程-第 6 步:添加对测试仪表板的支持

CMake教程-第 6 步:添加对测试仪表板的支持

  • 1 CMake教程介绍
  • 2 学习步骤
    • Step 1: A Basic Starting Point
    • Step 2: Adding a Library
    • Step 3: Adding Usage Requirements for a Library
    • Step 4: Adding Generator Expressions
    • Step 5: Installing and Testing
    • Step 6: Adding Support for a Testing Dashboard
    • Step 7: Adding System Introspection
    • Step 8: Adding a Custom Command and Generated File
    • Step 9: Packaging an Installer
    • Step 10: Selecting Static or Shared Libraries
    • Step 11: Adding Export Configuration
    • Step 12: Packaging Debug and Release
  • 3 Step 6: Adding Support for a Testing Dashboard
    • 3.1 Exercise 1 - Send Results to a Testing Dashboard
      • 3.1.1 目标
      • 3.1.2 Helpful Resources(有用的资源)
      • 3.1.3 Files to Edit(需编辑的文件)
      • 3.1.4 Getting Started(入门指南)
      • 3.1.5 Build and Run(构建并运行)
      • 3.1.6 解决方案

该文档是基于CMake的官方教程翻译而来,并稍微添加了自己的理解:

cmake的官方网站为:CMake Tutorial

1 CMake教程介绍

The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address. Seeing how various topics all work together in an example project can be very helpful.
CMake 教程提供了一个循序渐进的指南,涵盖了 CMake 可帮助解决的常见构建系统问题。在一个示例项目中了解各个主题是如何协同工作的,会非常有帮助。

2 学习步骤

The tutorial source code examples are available in this archive. Each step has its own subdirectory containing code that may be used as a starting point. The tutorial examples are progressive so that each step provides the complete solution for the previous step.
本文档中提供了教程源代码示例。每个步骤都有自己的子目录,其中包含可用作起点的代码。教程示例是循序渐进的,因此每一步都提供了前一步的完整解决方案。

Step 1: A Basic Starting Point

  • Exercise 1 - Building a Basic Project
  • Exercise 2 - Specifying the C++ Standard
  • Exercise 3 - Adding a Version Number and Configured Header File

Step 2: Adding a Library

  • Exercise 1 - Creating a Library
  • Exercise 2 - Adding an Option

Step 3: Adding Usage Requirements for a Library

  • Exercise 1 - Adding Usage Requirements for a Library
  • Exercise 2 - Setting the C++ Standard with Interface Libraries

Step 4: Adding Generator Expressions

  • Exercise 1 - Adding Compiler Warning Flags with Generator Expressions

Step 5: Installing and Testing

  • Exercise 1 - Install Rules
  • Exercise 2 - Testing Support

Step 6: Adding Support for a Testing Dashboard

  • Exercise 1 - Send Results to a Testing Dashboard

Step 7: Adding System Introspection

  • Exercise 1 - Assessing Dependency Availability

Step 8: Adding a Custom Command and Generated File

Step 9: Packaging an Installer

Step 10: Selecting Static or Shared Libraries

Step 11: Adding Export Configuration

Step 12: Packaging Debug and Release

3 Step 6: Adding Support for a Testing Dashboard

Adding support for submitting our test results to a dashboard is simple. We already defined a number of tests for our project in Testing Support. Now we just have to run those tests and submit them to CDash.

3.1 Exercise 1 - Send Results to a Testing Dashboard

3.1.1 目标

Display our CTest results with CDash.
使用CDash显示我们的CTest结果

3.1.2 Helpful Resources(有用的资源)

  • ctest(1)
  • include()
  • CTest

3.1.3 Files to Edit(需编辑的文件)

  • CMakeLists.txt

3.1.4 Getting Started(入门指南)

For this exercise, complete TODO 1 in the top-level CMakeLists.txt by including the CTest module. This will enable testing with CTest as well as dashboard submissions to CDash, so we can safely remove the call to enable_testing().
在本练习中,请完成顶层 CMakeLists.txt 的 TODO 1,加入 CTest 模块。这将启用 CTest 测试以及向 CDash 提交仪表板,因此我们可以放心地移除对 enable_testing() 的调用。

We will also need to acquire a CTestConfig.cmake file to be placed in the top-level directory. When run, the ctest executable will read this file to gather information about the testing dashboard. It contains:
我们还需要获取 CTestConfig.cmake 文件,并将其放置在顶层目录中。运行时,ctest 可执行文件将读取该文件,以收集有关测试仪表板的信息。该文件包含

  • The project name
  • 工程的名称
  • The project “Nightly” start time
  • 项目的每次启动时间
    • The time when a 24 hour “day” starts for this project.
    • 该项目在每天24小时的启动时间
  • The URL of the CDash instance where the submission’s generated documents will be sent
  • CDash 实例的 URL,提交生成的文件将被发送到该 URL

For this tutorial, a public dashboard server is used and its corresponding CTestConfig.cmake file is provided for you in this step’s root directory. In practice, this file would be downloaded from a project’s Settings page on the CDash instance intended to host the test results. Once downloaded from CDash, the file should not be modified locally.
本教程使用的是公共 dashboard 服务器,其相应的 CTestConfig.cmake 文件位于本步骤的根目录中。在实际操作中,该文件将从用于托管测试结果的 CDash 实例上的项目设置页面下载。从 CDash 下载后,不应在本地修改该文件。

CTestConfig.cmake
set(CTEST_PROJECT_NAME "CMakeTutorial")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")

set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=CMakeTutorial")
set(CTEST_DROP_SITE_CDASH TRUE)

3.1.5 Build and Run(构建并运行)

Note that as part of the CDash submission some information about your development system (e.g. site name or full pathnames) may displayed publicly.
请注意,作为 CDash 提交的一部分,您开发系统的某些信息(如站点名称或完整路径名)可能会公开显示。

To create a simple test dashboard, run the cmake executable or the cmake-gui to configure the project but do not build it yet. Instead, navigate to the build directory and run:
要创建一个简单的测试仪表板,请运行 cmake 可执行文件或 cmake-gui 配置项目,但先不要编译。相反,请导航至构建目录并运行:

ctest [-VV] -D Experimental

Remember, for multi-config generators (e.g. Visual Studio), the configuration type must be specified:
请记住,对于多配置生成器(如 Visual Studio),必须指定配置类型:

ctest [-VV] -C Debug -D Experimental

Or, from an IDE, build the Experimental target.
或者在继承开发环境中构建实验目标。

The ctest executable will build the project, run any tests, and submit the results to Kitware’s public dashboard: https://my.cdash.org/index.php?project=CMakeTutorial.
ctest 可执行程序将构建项目、运行任何测试,并将结果提交到 Kitware 的公共控制面板:https://my.cdash.org/index.php?project=CMakeTutorial。

3.1.6 解决方案

The only CMake code changed needed in this step was to enable dashboard submissions to CDash by including the CTest module in our top-level CMakeLists.txt:
在这一步中,唯一需要修改的 CMake 代码是在顶层 CMakeLists.txt 中加入 CTest 模块,以启用向 CDash 提交仪表盘的功能:

TODO 1: Click to show/hide answer

TODO 1: CMakeLists.txt
include(CTest)

你可能感兴趣的:(cmake,CMake添加对测试仪表板支持,第6步:添加对测试仪表板的支持,CMake教程)