May 28th, 2024

Visual Studio Code CMake Tools Extension 1.18 Update: Quick Start with CMake and more…

Sinem Akinci
Product Manager II

The May release of CMake Tools in VS Code is now available. With this release, we have some new updates to the extension to improve CMake integrations with the extension’s support.

Some major highlights include improvements to the CMake: Quick Start command and support for CMake presets v7 and v8.

To view the full list of updates with this release, please look at our CHANGELOG. This release features 2 contributions from our open-source community (@OrkunTokdemir and @hippo91). We greatly appreciate your continued support!

CMake: Quick Start Updates

The CMake: Quick Start command is a command that assists users in building an existing simple project with CMake when they do not have a CMakeLists.txt file in their project. It generates a CMakeLists.txt file for you, so that you can add CMake support to your project. 

The CMake: Quick Start command in the command palette in VS Code

This command has been updated to integrate better with your pre-existing project needs by:

  • Allowing you to add pre-existing .cpp files as targets in the generated CMakeLists.txt file
  • Allowing you to dynamically add other support to your CMakeLists.txt file, such as CPack (packaging) and CTest (testing)
  • Adding support to generate a CMakePresets.json file for your project based on custom configurations or pre-existing compilers on your machine.

Now, when you are starting up a CMake project and need to onboard .cpp files to CMake, you are set up for ultimate levels of customizability and success.

How it works

When you invoke CMake: Quick Start via the command palette (Ctrl+Shift+P), you’ll be prompted to name your project. From there, we’ve enhanced our experience to dynamically generate a CMakeLists.txt file and CMakePresets.json file.

For the CMakeLists.txt file, you will now have additional options to add CPack and CTest support to your CMakeLists.txt file.

The option in the command palette to select CPack and CTest support in a multi-select formatAdditionally, you can select to add any pre-existing .cpp files in your projects as CMake targets in your CMakeLists.txt file, so that you can run these with CMake. If you do not select a pre-existing .cpp file or you don’t have any pre-existing .cpp files, the extension will generate a new “Hello World” .cpp file and add it as a target.

The dropdown view in the command palette to add existing .cpp files as targets in the CMakeLists.txt fileThis will generate the CMakeLists.txt file that your project will need to build with CMake.

It will then enter an optional workflow to generate a CMakePresets.json. CMake presets are a central JSON file that store CMake configurations for CMake actions like configure, build, test, and more. This allows you to seamlessly move your project between desired configurations, other colleagues, different operating systems, and other IDEs.

In this workflow, the command palette will prompt you to select a configuration type to use as a configure preset. You can generate from a custom configure preset, a toolchain file, or by scanning your machine for compilers. If you’re just getting started with CMake, we’d recommend creating from compilers. For more on configure presets, please read our docs.

Option to select a configure preset in the CMake Quick Start command palette, with toolchain file, custom, and compiler options

After going through the entire updated workflow, you’ll be able to build your .cpp files using CMake with a new CMakeLists.txt file and CMakePresets.json file.

CMake Presets v7 and v8 Support

We have added support for CMake presets files up to version 8 in our VS Code extension.  

CMake presets v7 includes the support for the trace property in your configure presets. To learn more about the trace property, please visit the CMake Presets official documentation by Kitware. 

What do you think?

Download the CMake Tools extension for Visual Studio Code and let us know what you think. We would love to see what you contribute to our repoand we are active on reviews and collaboration. Please create an issue if there’s anything you’d like to see and upvote/downvote any existing issues. Comment below or reach us via email at visualcpp@microsoft.com or via X at @VisualC. 

Author

Sinem Akinci
Product Manager II

C++ Product Manager working on Copilot, CMake, and Linux experiences in Visual Studio and VS Code

0 comments

Discussion are closed.

Feedback