Skip to content

cmake -E env: Add --modify flag

When cmake -E env is given the --modify flag, try to parse the following argument as an ENVIRONMENT_MODIFICATION operation and apply it to the environment.

This generalizes --unset=:

  1. When implementing ENVIRONMENT_MODIFICATION features for other CMake commands, the MYVAR=OP:VALUE strings do not need to be translated to OP-specific flags.
  2. This provides a natural and consistent extension point to introduce new operations without introducing very many flags.
  3. Users need to learn only one syntax to access the same functionality.

There is one difference between the behavior here as compared to CTest's interpretation of the ENVIRONMENT_MODIFICATION test property. The MYVAR=reset: command when run in cmake -E env will reset MYVAR to whatever its value was when cmake -E env launched, rather than try to checkpoint after plain MYVAR=VALUE options. This makes MYVAR=VALUE and --modify MYVAR=set:VALUE semantically equivalent.

Tagging @ben.boeckel since we talked about implementing this in the original issue.

Also, I am a new contributor here, so this would be my first MR if it is indeed merged. I have read the developer documentation, but please afford me a little extra patience if I messed something up. 🙂

Fixes: #16372 (closed)
Topic-rename: cmake-E-env-modify

Edited by Brad King

Merge request reports