# 第11章 打包项目

本章的主要内容有：

* 生成源代码和二进制包
* 使用CMake/pybind11构建的C++/Python项目，通过PyPI发布
* 使用CMake/CFFI构建C/Fortran/Python项目，通过PyPI发布
* 以Conda包的形式发布一个简单的项目
* 将Conda包作为依赖项发布给项目

目前为止，已经从源代码编译并安装了软件包——这意味着可以通过Git获取项目，并手动执行配置、构建、测试和安装。然而，在实际中，软件包通常是使用管理器来安装的，比如Apt、DNF、Pacman、pip和Conda。我们需要以各种格式发布我们的代码项目——作为源文件或二进制安装程序。

下图显示了使用CMake的项目的各个阶段，我们现在方案就是其中的打包时(PI)：

![](/files/-LmKs9Mq3NYlLAVC0eH6)

本章中，我们将探讨不同的打包策略。首先，讨论使用CMake中的工具CPack进行打包，还提供打包和上传CMake项目到Python包索引(PyPI, <https://pypi.org)和Anaconda云(https://anaconda.org> )的方法，这些都是通过包管理器pip和Conda (<https://conda.io/docs/> )分发包的平台。对于PyPI，我们将演示如何打包和分发混合C++/Python或C/Fortran/Python的项目。对于Conda，我们将展示如何对依赖于其他库的C++项目进行打包。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chenxiaowei.gitbook.io/cmake-cookbook/11.0-chinese.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
