[CMake] is it possbile to export environment varibles from cmake scripts?

Timenkov Yuri ytimenkov at parallels.com
Mon Jul 7 08:02:59 EDT 2008



On Monday 07 July 2008 15:53:00 Alexander Bubnov wrote:
> Hello!
>
> Below simple example to clarify the problem.
>
> My CMakeLists.txt:
>
> cmake_minimum_required(VERSION 2.6)
>
> set(ENV{MYVAR} "SOME VALUE")
> message("the value of MYVAR: " $ENV{MYVAR})
>
> the output:
>
> the value of MYVAR: SOME VALUE
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/alek/trial/cmake/CMakeExample
>
>
> after that I am typing: echo $MYVAR
> MYVAR: Undefined variable.
>
> Is it possible to export MYVAR to shell environment?
I don't think it's possible with any tool. Environment variables are 
propagated from parent process to child when the former creates start-up 
parameters (for exec* or CreateProcess calls) for the latter (as CMake and any 
other program (including shell) does when executes external utilities).

The "export" or "set" are keywords of command line interpreter itself which 
tell it to set appropriate environment variables for child processes.

As for CMake, you can try to execute script from CMakeLists.txt to see if it 
exports variables properly.

>
> Thanks in advance.



More information about the CMake mailing list