# CMake 安装

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

如果您的工作流程包括项目安装，您可能需要使用生成安装规则的 [CMake install](https://cmake.org/cmake/help/v3.12/command/install.html) 命令。

> **Tip:**
> CMake 安装   会调用构建目标，因此您无需单独调用   构建   操作。

Procedure: 配置安装

1. 将  install  命令放入您的 [CMakeLists.txt](cmakelists-txt-file.html) 文件中。

2. 通过   [DESTINATION dir]   字段设置  install  命令的安装路径。 这里有两个选项：

* 提供带有前导斜杠或驱动器号的完整路径。

* 使用相对路径，该路径将被解释为相对于 [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/v3.10/variable/CMAKE_INSTALL_PREFIX.html#variable:CMAKE_INSTALL_PREFIX) 变量的值（如果在 `CMake 选项` 部分的 `设置 | 构建、执行、部署 | CMake` 对话框中提供了该值）： ![CMake 安装选项](https://resources.jetbrains.com/help/img/idea/2026.3/cl_CmakeInstall_Prefix.png)

Procedure: 仅运行安装

1. 要仅运行安装，请从主菜单调用  `构建 | 安装` 。

Procedure: 在启动前运行安装

1. 在主菜单中，转到  `运行 | 编辑配置`  并选择您想要添加安装步骤的配置。

2. 在   启动前   区域中点击 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.general.add.svg) 并选择   安装  ：

![作为启动前步骤安装](https://resources.jetbrains.com/help/img/idea/2026.3/cl_CmakeInstall_BeforeLaunch.png)

> **Tip:**
> 如果您需要以 root 权限运行安装，请改用 [CMake Target](running-cmake-targets-before-launch.html) 选项。

3. 运行   或   调试   配置。

> **Note:**
> 为防止目标被构建两次，在添加   安装   后排除   构建   步骤。

最终，您在  install  命令中指定的目标将被构建并放入指定的目录中。

## See also

### 操作指南

[快速 CMake 教程](quick-cmake-tutorial.html) [CMake Profiles](cmake-profile.html) [在启动前运行 CMake 目标](running-cmake-targets-before-launch.html)

