# Meson 项目

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

> **TL;DR**
> Meson 版本  ：0.54 或更高版本

在 CLion 中，您可以创建、打开、构建和运行/调试 [Meson](https://mesonbuild.com) 项目。 Meson 支持所有平台以及所有本地和 [远程](remote-projects-support.html) 工具链，包括 [WSL](how-to-use-wsl-development-environment-in-product.html) 和 [Docker](clion-toolchains-in-docker.html)。

Procedure: 安装 Meson

1. 请按照官方的 [安装指南](https://mesonbuild.com/Getting-meson.html) 在您的系统上安装 Meson。

Procedure: 创建一个 Meson 项目

1. 从主菜单中选择  `文件 | 新建 | 项目`  或在欢迎屏幕上点击   新项目  。

2. 在左侧窗格中选择   Meson  。

3. 指定项目名称和类型，并选择语言标准：

![Meson 项目向导](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_wizard.png)

4. 点击   创建  。

CLion 将生成一个包含  `main.cpp`  和  `meson.构建`  的简单项目：

![一个新的 Meson 项目](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_wizard_generated.png)

> **Tip:**
> 您可以在  `设置 | 编辑器 | 文件和代码模板 | 其他`  中调整  `meson.构建`  文件模板。
>
> ![meson.构建 文件模板](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_filetemplate.png)

Procedure: 打开一个 Meson 项目

1. 从主菜单中选择  `文件 | 打开`  或在欢迎屏幕上点击   打开  。

2. 将 CLion 指向包含  `meson.构建`  的目录，然后点击   打开  。

CLion 将加载 Meson 项目结构，并在   构建   工具窗口中显示结果：

![Meson 项目已加载](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_loadproject.png)

Procedure: Meson 工具窗口

要打开 Meson 工具窗口，请点击右侧工具栏上的 ![](https://resources.jetbrains.com/help/img/idea/2026.3/clion-meson.icons.expui.toolWindowMeson.svg) 或从主菜单中选择  `视图 | 工具窗口 | Meson` 。

在此窗口中，您可以找到构建目标列表以及有用的命令，例如  `clean` 、  `install` 、  `test` 、  `configure`  等：

![Meson 工具窗口](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_toolwindow.png)

双击命令或目标以运行它。 悬停时的工具提示将显示将应用的确切命令：

![Meson 工具窗口工具提示](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_tw_tooltip.png)

使用工具栏执行项目操作并快速访问 [项目设置](#configure-meson)：

![Meson 窗口工具栏](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_toolwindow_toolbar.png)

Procedure: Meson 项目设置

1. 转到  `设置 | 构建、执行、部署 | Meson`  或点击 Meson 工具窗口中的 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.settings.svg)。

2. 使用此对话框配置以下内容：

* 工具链 — 选择一个已配置的 [工具链](how-to-create-toolchain-in-clion.html)。

* Meson 可执行文件 — 如果需要，指定一个自定义的 Meson 可执行文件。

* 设置选项 — 使用此字段添加额外的 Meson 命令，例如 `--native-file` 。

* 构建目录 — 检查或更改构建目录。

* 构建选项 — 如果需要，提供额外的构建选项。

![Meson 设置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_settings.png)

Procedure: 在 meson.构建 中进行辅助编辑

* CLion 会在  `meson.构建`  脚本中高亮显示代码。 要调整配色方案，请转到  `设置 | 编辑器 | 配色方案 | Meson` 。

![meson.构建 中的高亮显示](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_hightlight.png)

* 您可以使用 [结构视图](file-structure.html) 在  `meson.构建`  和  `meson_options.txt`  中导航到目标、依赖项和选项命令。

按 `Alt+7` (Windows), `⌘ 7` (macOS), `⌘ 7` (IntelliJ IDEA Classic (macOS)), `⌘ 7` (macOS System Shortcuts), `Alt+7` (XWin), `Alt+7` (GNOME), `Alt+7` (KDE), `Alt+7` (Emacs), `Alt+7` (Sublime Text), `⌘ 7` (Sublime Text (macOS)), `⌘ 3` (Xcode), `Ctrl+Alt+F` (Visual Studio), `⌃ ⌥ F` (Visual Studio (macOS)), `Ctrl+F11` (ReSharper), `⌃ F11` (ReSharper (macOS)), `Alt+7` (QtCreator), `⌘ 7` (QtCreator (macOS)), `Ctrl+7` (NetBeans), `Alt+7` (Eclipse), `⌘ 7` (Eclipse (macOS)) 打开结构工具窗口，或按 `Ctrl+F12` (Windows), `⌘ F12` (macOS), `⌘ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ 7` (macOS System Shortcuts), `Ctrl+F12` (XWin), `Ctrl+F12` (GNOME), `Ctrl+0` (KDE), `Ctrl+F12` (Emacs), `Ctrl+R` (Sublime Text), `⌘ R` (Sublime Text (macOS)), `⌃ 6` (Xcode), `Alt+\` (Visual Studio), `⌥ \` (Visual Studio (macOS)), `Ctrl+F12` (ReSharper), `⌘ F12` (ReSharper (macOS)), `Ctrl+F12` (QtCreator), `⌘ F12` (QtCreator (macOS)), `Ctrl+F12` (NetBeans), `Ctrl+F3` (Eclipse), `⌘ O` (Eclipse (macOS)) 打开结构弹出窗口。

![meson.构建 文件结构](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_structure.png)

Procedure: 重新加载项目

* 当您在  `meson.构建`  中进行更改时，CLion 会显示一个图标，提示重新加载项目：

![重新加载项目图标](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_reloadicon.png)

点击图标或按快捷键。

> **Tip:**
> 您可以在  `设置 | 编辑器 | 配色方案 | Meson`  中调整 Meson 文件的配色方案。

* 或者，在 Meson 工具窗口中点击 ![](https://resources.jetbrains.com/help/img/idea/2026.3/clion-meson-plugin.icons.expui.mesonReload.svg)。

另一种选择是使用   工具 | Meson   菜单：

![Meson 菜单操作](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_menuactions.png)

选择   清除并重新加载 Meson 项目   执行重新加载前的 [wipe](https://mesonbuild.com/Commands.html)。

> **Tip:**
> 在此菜单中，您还可以 [更改项目根目录](change-project-root-directory.html)。

Procedure: Meson 的运行/调试配置

* CLion 检测到项目构建目标并为其创建   原生应用程序   配置：

![Meson 项目配置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_configs.png)

* 在主菜单中，转到  `运行 | 编辑配置`  以设置其他参数（如果需要）：

![Meson 的本地应用程序配置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_configs_editconfigs.png)

Procedure: 构建、运行和调试

* 使用  `构建`  菜单中的操作来构建项目或选定的配置。

![构建菜单](https://resources.jetbrains.com/help/img/idea/2026.3/cl_meson_buildactions.png)

> **Tip:**
> 了解更多信息请参见 [构建操作](build-actions.html)。

* 要运行或调试您的程序，您可以使用配置小部件（点击 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.run.run.svg) 或 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.run.debug.svg)），  `运行`  菜单，或程序入口点旁的边栏图标：

![运行/调试的边栏图标](https://resources.jetbrains.com/help/img/idea/2026.3/调试配置](run-debug-configuration.html)

### 操作指南

[编辑器基础知识](using-code-editor.html) [文件结构](file-structure.html) [构建操作](build-actions.html) [运行应用程序](running-applications.html) [调试](debugging-code.html)

