question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to set environment variables when using cmake-presets

See original GitHub issue

For example, a preset that uses vcpkg requires a path to vcpkg.cmake, whose location may vary across machines. As the documentation suggests, this can be done by using $env{VCPKG_ROOT}.

Using the command line it is very easy to choose a vcpkg installation on a specific machine, or switch between vcpkg installations (to debug new versions of packages) by prepending the environment variable to the command line.

However, from inside vscode, there’s no easy way to set or modify this variable. This makes it difficult to work with presets with CMake-Tools.

Please add a setting for preset environment variables or enable the existing cmake.environment when using presets.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
globberwopscommented, May 5, 2021

This is currently a blocking issue for me and my team, and it is preventing us from switching from caches to presets.

Suppose you have say 3 different configure presets, 1-2 build presets for each configure preset, and maybe 2 different test presets. Now, as a developer, you want to use a compiler launcher, a different compiler or compiler version, or something like @sterin described. You would have to write an awful amount of user presets just to be able to do that and since the build/test presets all refer to a configure preset, you would have to override them as well.

Not being able to modify the environment defeats the whole purpose of the $penv{<variable-name>} macro in presets.

2reactions
sterincommented, May 4, 2021

It is definitely possible to this. It is also possible to use a symbolic link to point to the vcpkg installation. I just think this overcomplicates things.

While CMakePresets.json is supposed to be the sole source of truth, the use of environment variables to set machine-specific values is standard practice, it even appears in CMake Tools’ own documentation.

What CMake Tools is missing is a way to set these values, or override these values, from inside vscode without going through hoops.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake-presets(7) — CMake 3.25.1 Documentation
Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment...
Read more >
Configure and build with CMake Presets in Visual Studio
You can set environment variables by using the environment map. Environment variables are inherited through the inherits field, but you can ...
Read more >
CMakePresets.json: Appending to Path environment variable ...
Configuration fails because MSVC is no longer on the path for some reason and tries to use some other compiler that is on...
Read more >
How to specify default values for environment variables in ...
When using CMakePresets.json the documentation states that I can use either ... In the cli I use direnv to make sure some env...
Read more >
presets: sourcing environment scripts (#21619) · Issues - GitLab
however it would be great if the cmake presets would provide a feature to ... toolchains like the environment-setup-* scripts of yocto SDKs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found