[CMake] Setting environment variables for custom targets

Brandon Van Every bvanevery at gmail.com
Thu Nov 15 13:59:22 EST 2007


On Nov 15, 2007 1:53 PM, Josef Karthauser <joe.karthauser at geomerics.com> wrote:
> > -----Original Message-----
> > From: cmake-bounces+joe.karthauser=geomerics.com at cmake.org
> > [mailto:cmake-bounces+joe.karthauser=geomerics.com at cmake.org] On
> Behalf
> > Of Brandon Van Every
> > Sent: 15 November 2007 14:17
> > To: cmake at cmake.org
> > Subject: Re: [CMake] Setting environment variables for custom targets
> > > It doesn't appear that,
> > >
> > >         SET(ENV{MYVAR} FOO)
> > >        ADD_CUSTOM_TARGET(MYTARGET mycommand args),
> > >
> > > does the right thing, as the environment var MYVAR is only set
> during
> > > the cmake build, but not populated at build time and so not utilised
> > by
> > > the custom target.
> >
> > Wrap your external command in a CMake script.
> >
>
> How so?  Can you give me an example?

Call the script in your ADD_CUSTOM_TARGET using "cmake -P
myscript.cmake".  The script would contain something like:
SET(ENV{MYVAR} FOO)
EXECUTE_PROCESS(...) # whatever you want to do

However this environment is only going to last as long as the
execution of your CMake script.  That should be fine if all you're
trying to do is fire off an external tool and then continue
processing.  It's not enough if you're trying to set an environment
variable permanently, long after your build is over.  I think you
would have to do that on a system specific basis, I don't think CMake
has any mechanism for it.


Cheers,
Brandon Van Every


More information about the CMake mailing list