I think something like this could instead be added directly to cmake -E env as a --from-file= option or something like that. Other than bikeshedding the name of the option, the main design question is the format of the file itself:
How to unset variables? Maybe each line can be --unset=FOO to unset and FOO= to set, almost like a response file.
How to reference existing variables to be equivalent to cmake -E env "VAR=prefix:$VAR:suffix"? When that appears on the command line, the shell replaces $VAR before we even see it. In the file we’d need a syntax for that, and a way to escape it.
Are there existing formats for this used by other tools?
That sounds like a great idea! I was trying to think through some of the limitations of the env_file approach myself, like specifying envs both individually and from a file.
The docker format looks straightforward. The only drawback is that it doesn’t support referencing existing values. That’s probably okay for many use cases. To leave room for other formats later, we should indicate a format name or version in the option name, e.g. --from-file-v1=. Other name ideas, anyone?