Home > Software engineering >  How to set CMake build configuration in VSCode?
How to set CMake build configuration in VSCode?

Time:08-12

I'm using the CMake Tools extension in VSCode to build and run a C project on Windows.

Where do I set if the build configuration should be Debug or Release?

On Build, CMake Tools executes

"C:\Program Files\CMake\bin\cmake.EXE" --build c:/work/foobar/build --config Debug --target ALL_BUILD

How do I get the extension to build with --config Release?

CodePudding user response:

The CMake Tools extension sets up a lot of goodies, including a status bar panel for configuring various aspects of your build(s). In the status line various panels provided by VSCode and extensions can be enabled/disabled. And example including the CMake Tools mini panels appears below:

enter image description here

Note: I am not running VS Code on a Windows machine; mine is MacOS, but the premise is the same.

Anyway, if you click on the portion that says CMake: [Debug]: Ready a select-variant list should open near the top of the IDE in the location you're probably familiar seeing the general Command Palette open. It will look like this:

enter image description here

It is here you can change your selection from one build configuration type to another.

You can also do this via the main command palette by doing the following:

  1. Hit ctrl-shift-P (or cmd-shift-P on MacOS)
  2. Type CMake. The list should filter to just CMake command options.
  3. Scroll the list and choose CMake: Select Variant

The same aforementioned build variant options should present themselves.

  • Related