vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Use environment variables from cmake.[configure]environment when loading CMakePresets

Open tnixeu opened this issue 1 year ago • 2 comments

Brief Issue Summary

In Version 7 the includes allow to use of $penv{} macro expansion.

However, the environment variables defined in cmake.environment or cmake.configureEnvironment are not expanded there. Environment variables defined before starting vscode are expanded.

I have tried this with the latest pre-release version.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

tnixeu avatar Feb 08 '24 14:02 tnixeu

@tnixeu To confirm, what you are requesting is that in your Preset, you would like the cmake.environment and the cmake.configureEnvironment to be included in the penv context when the include field uses the $penv{} macro expansion?

Currently, this is not supported as we view the cmake.environment being used during Presets to be a more temporary measure, environment settings that are added to your environment when doing various commands like configure, etc.

However, this is a valid request to be made, so we can open it up to the community to upvote. Also, could you help us understand your use case for this more?

Thank you so much for your input!

gcampbell-msft avatar Feb 12 '24 18:02 gcampbell-msft

@gcampbell-msft Yes this what I had in mind.

I am currently using a variable in the include field in order to change which CMakeUserPreset.txt is loaded. They have have gotten to big to not check them in somewhere. However, I can not check it into the source directory directly, because it would be loaded in the CI environment or on a colleagues machine.

tnixeu avatar Feb 12 '24 22:02 tnixeu

@gcampbell-msft This seems to be related to #1836 and #3537. First of all, thank you so much for taking care of that issue!

However, I am still not able to override parts of the parent environment:

  1. Parent environment
SOME_PREFIX_PATH=<some/prefix/path>
  1. .vscode/settings.json
{
  "cmake.environment": {  // same for configureEnvironment
    "SOME_PREFIX_PATH": "<some/prefix/override>"
  }
}
  1. CMakePresets.json
...
"configurePresets": [
  ...
  "cacheVariables": {
    "CMAKE_PREFIX_PATH": "$penv{SOME_PREFIX_PATH}"  // same for $env
  }
  ...
  1. CMake configure
[driver] NOTE: You are configuring with preset Development Config, but there are some overrides being applied from your VS Code settings.
[proc] Executing command: /usr/bin/cmake ... "-DCMAKE_PREFIX_PATH=<some/prefix/path>" ...
  1. CMakeLists.txt
message(STATUS "SOME_PREFIX_PATH=$ENV{SOME_PREFIX_PATH}")
# [cmake] -- SOME_PREFIX_PATH=<some/prefix/override>

So it seems that the override from the folder settings sadly does not work for the preset. configureEnvironment or $env do not work either. However, CMake still picks up the overridden env variable in 5, although CMakeTools does not pick it up.

globberwops avatar Feb 19 '24 09:02 globberwops