Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set CMake build configuration in VSCode?

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?

like image 429
shinjin Avatar asked Nov 25 '25 04:11

shinjin


2 Answers

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.

like image 163
WhozCraig Avatar answered Nov 27 '25 20:11

WhozCraig


For information, the CMake Tools extension status bar is now hidden by default. To show the status bar as mentioned in the other comment, do the following:

  1. Extensions (Ctrl+Shift+X)

  2. CMake Tools > Extension Settings

  3. Search for "Status bar visibility" > select "visible"

CMake Tools status bar settings

Et voilà ! The status bar should appear at the bottom.

like image 36
Mrpopo Avatar answered Nov 27 '25 18:11

Mrpopo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!