[CMake] Setting environment variables

Gerhard Stengel gerhards2 at ast.dfs.de
Tue Sep 14 07:03:51 EDT 2010


Hi Johny,

I've experienced the same problem and unfortunately, I think there's no way to set them permanently. The reason seems to 
be that cmake invokes subshells for most of the commands, so the change of the environment variable only happens in the 
subshell and never reaches the parent.
I worked around this problem by executing a little script just before executing the command which needs the environment 
variables, like this:

add_custom_command(OUTPUT some_output.h
                    COMMAND source setup_env.sh\; my_command
                    DEPENDS my_dependencies)

setup_env.sh contains all the export commands to set the variables.

Hope that works for you

cheers

Gerhard

Am Dienstag 14 September 2010, 12:05:43 schrieb Johny:
> Hey,
> 
> I was trying to setup my environment variables before i start a build ,
> but they do not seem to be working at all. I basically have a Ctest
> script called driver.ctest which includes another file called envsetup
> at the beginning.
> 
> envsetup contains a list of set(ENV{VAR1} VALUE) and sometimes a few
> execute_process calls which store the output into an environment
> variable. However once the driver.ctest script gets to the building part
> the build fails as the environment variables are not set properly.
> 
> I also tried running the envsetup script alone by using the cmake -P
> command, when the script runs it set the values and outputs it
> correctly, however after the script finishes execution the environment
> is still unchanged. I want to set the environment variables permanently.
> 
> Is there some way to do this ?
> 
> Cheers
> Johny
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list