CMake官方教程中文翻译 Step 12: Packaging Debug and Release

鉴于自己破烂的英语,所以把cmake的官方文档用 谷歌翻译 翻译下来方便查看。
英语好的同学建议直接去看cmake官方文档(英文)学习:地址 点这里
或复制:https://cmake.org/cmake/help/latest/guide/tutorial/index.html

因为官方文档有点多,所以只截取CMake Tutorial的 step1——step12 进行翻译,这是第12步的翻译,以下是每一步的翻译链接:
Documentation » CMake Tutorial » Step 1: A Basic Starting Point
Documentation » CMake Tutorial » Step 2: Adding a Library
Documentation » CMake Tutorial » Step 3: Adding Usage Requirements for a Library
Documentation » CMake Tutorial » Step 4: Adding Generator Expressions
Documentation » CMake Tutorial » Step 5: Installing and Testing
Documentation » CMake Tutorial » Step 6: Adding Support for a Testing Dashboard
Documentation » CMake Tutorial » Step 7: Adding System Introspection
Documentation » CMake Tutorial » Step 8: Adding a Custom Command and Generated File
Documentation » CMake Tutorial » Step 9: Packaging an Installer
Documentation » CMake Tutorial » Step 10: Selecting Static or Shared Libraries
Documentation » CMake Tutorial » Step 11: Adding Export Configuration
[Documentation » CMake Tutorial » Step 12: Packaging Debug and Release]

谷歌翻译可能有错,此文档的目的仅是加快观看英文官方文档的速度,所以请结合英文官方文档观看

Step 12: Packaging Debug and Release

注意:此示例对单配置生成器有效,不适用于多配置生成器(例如 Visual Studio)。

默认情况下,CMake 的模型是构建目录仅包含单个配置,无论是 Debug、Release、MinSizeRel 还是 RelWithDebInfo。 但是,可以设置 CPack 来捆绑多个构建目录并构建一个包含同一项目的多个配置的包。

首先,我们要确保调试和发布版本对将安装的库使用不同的名称。 让我们使用 d 作为调试库的后缀。

在顶级 CMakeLists.txt 文件的开头附近设置 CMAKE_DEBUG_POSTFIX:

CMakeLists.txt
set(CMAKE_DEBUG_POSTFIX d)

add_library(tutorial_compiler_flags INTERFACE)

以及教程可执行文件上的 DEBUG_POSTFIX 属性:

CMakeLists.txt
add_executable(Tutorial tutorial.cxx)
set_target_properties(Tutorial PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)

我们还将版本编号添加到 MathFunctions 库。 在 MathFunctions/CMakeLists.txt 中,设置 VERSION 和 SOVERSION 属性:

MathFunctions/CMakeLists.txt
set_property(TARGET MathFunctions PROPERTY VERSION “1.0.0”)
set_property(TARGET MathFunctions PROPERTY SOVERSION “1”)

从 Step12 目录中,创建 debug 和 release 子目录。 布局将如下所示:

  • Step12
    • debug
    • release

现在我们需要设置调试和发布版本。 我们可以使用 CMAKE_BUILD_TYPE 来设置配置类型:

cd debug
cmake -DCMAKE_BUILD_TYPE=Debug …
cmake --build .
cd …/release
cmake -DCMAKE_BUILD_TYPE=Release …
cmake --build .

现在调试和发布版本都已完成,我们可以使用自定义配置文件将两个版本打包到单个版本中。 在 Step12 目录中,创建一个名为 MultiCPackConfig.cmake 的文件。 在此文件中,首先包含由 cmake 可执行文件创建的默认配置文件。

接下来,使用 CPACK_INSTALL_CMAKE_PROJECTS 变量指定要安装的项目。 在本例中,我们想要同时安装调试和发布。

MultiCPackConfig.cmake
include(“release/CPackConfig.cmake”)

set(CPACK_INSTALL_CMAKE_PROJECTS
“debug;Tutorial;ALL;/”
“release;Tutorial;ALL;/”
)

从 Step12 目录中,运行 cpack,并使用 config 选项指定我们的自定义配置文件:

cpack --config MultiCPackConfig.cmake

相关推荐

  1. CMake官方教程11--加入导出设置

    2024-02-01 08:12:03       16 阅读
  2. CMake官方教程4--使用表达式生成器

    2024-02-01 08:12:03       20 阅读
  3. CMake官方教程9--打包文件

    2024-02-01 08:12:03       19 阅读
  4. CMake官方教程6--为CDash提供支持

    2024-02-01 08:12:03       18 阅读
  5. CMake官方教程8--自定义命令和生成文件

    2024-02-01 08:12:03       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-01 08:12:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-01 08:12:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-01 08:12:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-01 08:12:03       20 阅读

热门阅读

  1. C++ 结构体的构造函数

    2024-02-01 08:12:03       32 阅读
  2. 面阵相机拍摄运动的物体怎样保证图像清晰

    2024-02-01 08:12:03       40 阅读
  3. TensorFlow2实战-系列教程14:Resnet实战2

    2024-02-01 08:12:03       42 阅读
  4. 3D Gaussian Splatting-实时辐射场渲染技术

    2024-02-01 08:12:03       33 阅读
  5. TensorFlow2实战-系列教程15:Resnet实战3

    2024-02-01 08:12:03       39 阅读
  6. CSS 中的 :is(), :where(), 和 :has() 选择器简介

    2024-02-01 08:12:03       32 阅读
  7. 使用certbot申请https通配符证书【阿里云篇】

    2024-02-01 08:12:03       38 阅读
  8. K8S网络

    K8S网络

    2024-02-01 08:12:03      32 阅读
  9. k8s学习-数据管理

    2024-02-01 08:12:03       29 阅读
  10. brpc之单例

    2024-02-01 08:12:03       33 阅读
  11. Qt之connect函数使用

    2024-02-01 08:12:03       30 阅读
  12. 原型和继承

    2024-02-01 08:12:03       33 阅读
  13. electron从入门到打包exe

    2024-02-01 08:12:03       44 阅读