How to pass command line arguments to cmake in vscode?

Viewed 3797

I cloned a github repo. It has been set to built with cmake. I now want to build it in vscode, but I cannot find a place to set cmake command line argument.

When I execute cmake configure in vscode, it complains cannot find some headers or libs. I test in terminal, when I set -D arguments, this error can be solved.

So, I wonder is there a place to pass cmake command line arguments in vscode?

Thank you very much!

1 Answers

Passing information onto CMake in VSCode happens in the settings.json file.

You need to install the CMake Tools extention first.

Then, open the command pallet in VSCode with Ctrl+Shift+P and type Open Settings.

Once selected, VSCode will show a settings.json file where you should add cmake.configureArgs e.g.:

{
 "other":"settings",
 "cmake.configureArgs": [
        "-DOPTIONA=ON",
        "-DOPTIONB=ON"
    ],
}

The cmake.configureArgs array of arguments is the same as you would normally use during a command-line cmake configure e.g.

cmake -DOPTIONA=ON -DOPTIONB=ON ..
Related