[CMake] environment variables & scope

Alexander Neundorf a.neundorf-work at gmx.net
Tue Oct 20 17:28:00 EDT 2009


On Tuesday 20 October 2009, James C. Sutherland wrote:
> How do I set an environment variable so that it is visible globally in
> CMake?  Specifically, I want to have it visible when I run something
> like:
>
> #-----------------------------------
> # set the environment variable value
> set( ENV{myVariable} ... )
>
> # run a test through a CMake script that requires the environment
> variable set above.
> add_test( myTest
>    ${CMAKE_COMMAND}
>    -D exe_name:STRING=myExecutable
>    -P ${PROJECT_SOURCE_DIR}/test_problems/run_test.cmake
>    )
> #-----------------------------------
>
> In the "run_test.cmake" file I would like to have "myVariable"
> available as an environment variable, but it is not, despite the fact
> that it was set prior to the execution of "run_test.cmake".
>
> What am I missing here?

The environment variable you set above is only set during that cmake run, i.e. 
it is not set during e.g. the makefile invocation and also not during ctest 
run.

If you need special env.vars set during testing, you either can wrap it into 
an extra shell script which does that or use cmake 2.8.0/current cvs HEAD, 
there you can set an ENVIRONMENT property on the tests.

Alex


More information about the CMake mailing list