Clarify how environment variables are propagated
The documentation says this about setting env vars:
set(ENV{<variable>} <value>...)
Set the current process environment to the given value.
It is however not clear how process environment is propagated to subprocesses.
By experimentation I found out that variables are inherited when using execute_process
but not with add_custom_target
and add_custom_command
.
This makes sense if we interpret "current process" as just the cmake process processing the script file, not the make
process or any other build tool producing output. I think this should at least be emphasized in the documentation somehow, I'm not the only person running into this problem.
Ideally, it would be nice to have a way to specify env vars for custom targets / commands. I now know that I can use ${CMAKE_COMMAND} -E env
but I only learned that through StackOverflow; it should probably be mentioned in docs for add_custom_target
and add_custom_command
. (Also it's kind of verbose, but that's not a primary problem.)
Thanks! BR