[CMake] $ENV usage and documentation

Brandon Van Every bvanevery at gmail.com
Sun Jan 27 22:28:03 EST 2008


On Jan 27, 2008 8:34 PM, Alan W. Irwin <irwin at beluga.phys.uvic.ca> wrote:
> I would like to be able to read arbitrary environment variables from within
> cmake.  The 2.4.8 documentation only refers to $ENV once as "$ENV{PATH}" in
> an extremely narrow context (the TO_CMAKE_PATH signature of the FILE command).
> However, when I tried, e.g.,
>
> SET(pc_path "$ENV{PKG_CONFIG_PATH}")
>
> it seemed to work.  Is this usage supported in general?

As far as I know.  You can test all these things out with trivial
scripts to prove that they work or don't work.

> The current documentation has a number of different references to ENV.
> It refers to
>
> $ENV{PATH}
>
> one place (in a narrow context as noted above),
>
> ENV var
>
> several places, but in extremely specific contexts (which I presume could be
> replaced by $ENV{var})
>
> and
>
> ENV{PATH}
>
> in one place (an example showing how to use SET to write
> the PATH environment variable).
>
> Please document $ENV for reading and ENV for writing arbitrary environment
> variables in at least the CVS version.  A logical place for this general
> documentation might be the SET command since as noted above that already
> gives an example for writing the PATH environment variable.

It would be best if you file a (documentation, text) bug report for
this.  Preferably with the wordsmithing you think should be used, and
where it should be used, based on what you have determined works
properly.  I've been doing this for various documentation
embellishments in recent months, and they are getting acted upon and
closed.

One gotcha about set(ENV{var} blah) is that it only sets the CMake
configuration environment.  It doesn't exist in the build environment,
as CMake is gone and we're not running under CMake's choice of shell
anymore.  This gotcha should also be noted in the set() docs.


Cheers,
Brandon Van Every


More information about the CMake mailing list