We're hiring!
*

Meson & VSCode: Develop your project in a modern IDE

Xavier Claessens avatar

Xavier Claessens
April 18, 2023

Share this post:

Reading time:

Meson VSCode Extension

Want to develop your Meson project in a modern IDE? Make sure to install Meson VSCode extension which is now fully functional with the recent release of Meson 1.1.0!

VSCode, like its fully open-source sibling VSCodium, is a popular IDE (integrated development environment) from Microsoft that is highly configurable with extensions. Meson is the open source build system used by most GNOME and Freedesktop projects. Meson provides introspection data to integrate your project into your IDE, for tasks such as building and running your project. Meson also provides an official VSCode extension that uses that information to provide all functionalities presented here.

Examples below require a recent version of Meson and its VSCode extension:

  • Meson 1.1.0
  • Extension 1.9.0

Syntax highlighting

The extension provides complete Meson language grammar support for meson.build and meson_options.txt files.

Automatic project configuration

The first time a Meson project is opened, VSCode will ask if you wish to configure it. By default it will run meson setup builddir, default options are configuration in the extension settings.

Once your project is configured, or if it was already configured manually in builddir/, the extension will:

  • Add build and test tasks.
  • Setup C/C++ Intellisense.
  • Create an environment file to be used to launch commands in Meson's developer environment.

Build and test tasks

All tasks can be found in Terminal → Run Task..., or with Ctrl+Shift+P shortcut, search for meson in the dropdown menu.

The default build task will (re)compile the whole project. It can be triggered with Ctrl+Shift+B shortcut.

In addition, individual targets can be compiled by simply clicking them in the Meson sidebar. At the top you'll find the main project targets; subproject targets can be found below.

Each target also has an open icon to open the meson.build file where that target is defined and a submenu that lists all source files used to build that target. This allows browsing the project source tree by targets instead of relying on the filesystem hierarchy.

Likewise, the sidebar contains all unit tests that are sorted per subproject. Clicking one of them will run it.

To run all tests from all subprojects at once, search Meson: Run tests in the Terminal → Run Task... menu, or Ctrl+Shift+PMeson: Run Unit Testsall.

C/C++ Intellisense

If Microsoft's Intellisense extension is installed, it will be automatically configured to use the compile_commands.json file generated by Meson in your build directory. This allows VSCode's C and C++ syntax analyzer to find and include the paths and CFLAGS needed.

Launch task in developer environment

Meson provides a developer environment to run executables from your project without installing it. It consists on a set of environment variables that needs to be set in order to properly run the project, such as LD_LIBRARY_PATH, GST_PLUGIN_PATH (GStreamer), etc.

The Meson VSCode extension exports that environment into a file that can be used by VSCode's launch.json file's envFile attribute.

If your project provides a .vscode/launch.json file, F5 will run the program in the debugger, allowing you to inspect a variable's value and step line by line into your code directly in VSCode.

See GStreamer's launch.json file as example: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/.vscode/launch.json.

Comments (5)

  1. q4a:
    Apr 18, 2023 at 06:02 PM

    What about breakpoints?
    https://github.com/microsoft/vscode-cpptools/issues/9503 - issue about breakpoints with strcmp didn't fixed since 24.06.2022
    https://github.com/microsoft/vscode-cpptools/issues/5676 - issue about string breakpoints condition like text=="from" didn't fixed since 23.06.2020
    https://github.com/microsoft/vscode-cpptools/issues/714 - issue about breakpoints with hit count didn't fixed since 11.05.2017.. 6 years have passed((

    Reply to this comment

    Reply to this comment

    1. Xavier Claessens:
      Apr 18, 2023 at 06:34 PM

      Hi,

      Debugging indeed has limitations, but those issues are not related to Meson integration. Unfortunately we are not affiliated with Microsoft so there is nothing we can do about them.

      Reply to this comment

      Reply to this comment

      1. q4a:
        Apr 18, 2023 at 06:51 PM

        Topic says "Develop your project in a modern IDE".
        Debugging is a significant part of the development, so it should not be ignored.
        I'm using QtCreator for cmake and meson projects - it's open source and has better debugging support.
        It's good when you have different options, but VS Code is less convenient for now.

        Reply to this comment

        Reply to this comment

  2. scarhill:
    Jan 04, 2025 at 06:55 PM

    Is there any way to pass the --cross-file option to meson setup? Thanks!

    Reply to this comment

    Reply to this comment


Add a Comment






Allowed tags: <b><i><br>Add a new comment:


Search the newsroom

Latest Blog Posts

Writing a Rust GPU kernel driver: a brief introduction on how GPU drivers work

06/08/2025

This second post in the Tyr series dives deeper into GPU driver internals by using the Vulkan-based VkCube application to explain how User…

A practical debugging guide for media driver developers

22/07/2025

Getting into kernel development can be daunting. There are layers upon layers of knowledge to master, but no clear roadmap, especially when…

Quick notes from the GStreamer Spring Hackfest 2025

15/07/2025

This past May, we met with the community at the GStreamer Spring Hackfest in Nice, France, and were able to make great strides, including…

PipeWire workshop 2025: Updates on video transport, Rust efforts, TSN networking, and Bluetooth support

03/07/2025

As part of the activities Embedded Recipes in Nice, France, Collabora hosted a PipeWire workshop/hackfest, an opportunity for attendees…

Coccinelle for Rust progress report

25/06/2025

In collaboration with Inria, the French Institute for Research in Computer Science and Automation, Tathagata Roy shares the progress made…

Linux Media Summit 2025 recap

23/06/2025

Last month in Nice, active media developers came together for the annual Linux Media Summit to exchange insights and tackle ongoing challenges…

Open Since 2005 logo

Our website only uses a strictly necessary session cookie provided by our CMS system. To find out more please follow this link.

Collabora Limited © 2005-2025. All rights reserved. Privacy Notice. Sitemap.