# 第8章 超级构建模式

本章的主要内容如下：

* 使用超级级构建模式
* 使用超级构建管理依赖项:Ⅰ.Boost库
* 使用超级构建管理依赖项:Ⅱ.FFTW库
* 使用超级构建管理依赖项:Ⅲ.Google Test框架
* 使用超级构建支持项目

每个项目都需要处理依赖关系，使用CMake很容易查询这些依赖关系，是否存在于配置项目中。第3章，展示了如何找到安装在系统上的依赖项，到目前为止我们一直使用这种模式。但是，当不满足依赖关系，我们只能使配置失败，并向用户警告失败的原因。然而，使用CMake可以组织我们的项目，如果在系统上找不到依赖项，就可以自动获取和构建依赖项。本章将介绍和分析`ExternalProject.cmake`和`FetchContent.cmake`标准模块，及在超级构建模式中的使用。前者允许在构建时检索项目的依赖项，后者允许我们在配置时检索依赖项(CMake的3.11版本后添加)。使用超级构建模式，我们可以利用CMake作为包管理器：相同的项目中，将以相同的方式处理依赖项，无论依赖项在系统上是已经可用，还是需要重新构建。接下来的5个示例，将带您了解该模式，并展示如何使用它来获取和构建依赖关系。

**NOTE**:*这两个模块都有大量的在线文档。`ExternalProject.cmake`，可以参考*<https://cmake.org/cmake/help/v3.5/module/ExternalProject.html> *。`FetchContent.cmake`，可以参考*<https://cmake.org/cmake/help/v3.11/module/FetchContent.html> *。*


---

# 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/8.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.
