[CMake] Enviromentvariable

Brandon Van Every bvanevery at gmail.com
Wed Jul 4 14:41:01 EDT 2007


On 7/4/07, Camek, Alexander <Alexander.Camek at elektrobit.com> wrote:
> Hi List,
>
> I need for my build to set some enviroment variables.
> With SET(ENV{FOO} ) i can only set the enviroment variable for cmake
> time, but how do i set the variable for build time?

Good question.  A "cmake -P" script with a SET(ENV{myvar} whatever)
command in it can set the environment for the duration of the script.
But it cannot set it permanently, it goes away as soon as the script
returns.  So if the following workflow is acceptable:

  do an ADD_CUSTOM_COMMAND
    run a cmake -P script
      set an ENV{myvar}
        run a 3rd party build component and return

then you'd be fine.  But there's no portable way to set an environment
variable permanently as far as I can see.   I think you have to write
different environment setters for every platform if you want that.

> Do I have to do that with an custom command?

That's the right time to issue the command.

Realize that you don't need/want to set environment variables for
build components under your control.  You just pass CMake variables
around to things that need them.  However, you may have legacy code
that you can't change, or 3rd party code that you have no control
over.


Cheers,
Brandon Van Every


More information about the CMake mailing list