# 在启动前运行 CMake 目标

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

CMake 目标可以在运行/调试配置启动前自动执行。 这包括内置的 CMake 目标，例如  `all`  或  `clean` ，以及通过  `add_executable`  或  `add_custom_target`  指定的目标。

Procedure:

1. 在主菜单中，转到  `运行 | 编辑配置`  并选择一个 [CMake 应用程序](run-debug-configuration-makefile-application.html) 或测试配置进行编辑。

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

![在启动前添加 CMake 目标](https://resources.jetbrains.com/help/img/idea/2026.3/cl_rdconfig_beforelaunch_cmaketagrets.png)

> **Tip:**
> 对于  `install`  目标，您还可以使用另一个名为   安装   的任务。 请参阅 [CMake 安装](using-cmake-install.html#configure-install)。

3. 在打开的对话框中，选择所需的目标：

![在启动前添加 CMake 目标](https://resources.jetbrains.com/help/img/idea/2026.3/cl_rdconfig_beforelaunch_cmaketargets_dialog.png)

选中   以 root 权限运行   复选框以管理员权限运行目标：

![选项：以 root 权限运行启动前目标](https://resources.jetbrains.com/help/img/idea/2026.3/cl_rdconfig_beforelaunch_cmaketargets_root.png)

4. 保存设置。 下次运行或调试此配置时，指定的目标将在启动前执行。

> **Note:**
> 启动前   任务按照它们在列表中出现的顺序执行。

## See also

### 操作指南

[快速 CMake 教程](quick-cmake-tutorial.html) [CMake 安装](using-cmake-install.html)

