VSCode: Refer to CMakePresets.json-defined (configure/build) environment variable in tasks.json and/or launch.json

660 Views Asked by At

As the title says, with Visual Studio Code and CMake extension, in a C++ project that is configured via CMakePresets.json (define configure, build, test environments and compilers/toolchains), how can one refer to a environment variable defined in the JSON file?

For example, consider envvar VM_IP let's call it, that is different for each configuration: one VM for Ubuntu, another VM with Windows 10, and this is specified via "environment" property in CMakePresets.json for each configuration.

I would like to launch the target on the specific VM and use the appropriate IP without having to type IP in again duplicated in tasks.json (nor via its "envFile" property, as this is non-importable in CMakePresets.json)

Is there a macro expansion to call, perhaps something like ${cmake.configureEnvironment:VM_IP}, in tasks.json to get the envvar value?

0

There are 0 best solutions below