[CMake] Setting an environment variable when executing make script

Philip Lowman philip at yhbt.com
Sun Mar 29 21:46:40 EDT 2009


Here are some options:

1. Manually set your environment variables in Control Panel->System or your
~./.bashrc or shell configuration file of choice.
2. If you need multiple different configurations define them in multiple
files which you source into your existing shell.  In Linux you would do
something like ". new_settings.sh".  In Windows I'm guessing you just run a
".bat" file with the settings in it.
3. Use bash, tcsh, etc. functions (Linux only I believe)
4. Use CMake to create a script that sets environment variables and invokes
a new console ("bash") or a graphical window ("konsole)
5. Use CMake to create a script that you then manually source in via ".
new_settings.sh" or running a batch file

I'm sure there are plenty more.  The major problem of course is that CMake
is not meant to create persistent environment variables because it's not
meant to launch your build tool of choice, be that Visual Studio,
"gnome-terminal", Kdevelop, eclipse, etc.

On Sun, Mar 29, 2009 at 4:15 PM, James Bigler <jamesbigler at gmail.com> wrote:

> Sorry about the typo.
>
> In order to have the environment variable persist you need to set it in the
> parent process. I know if no mechanism of setting environment variables in a
> parent process using CMake or otherwise.
>
> The script mechanism I described was intended to set the environment before
> calling the command you need. In essense the CMake script becomes the parent
> process from which all child processes will inherit environment variables
> from.
>
> James
>
> On Mar 29, 2009, at 10:33 AM, Carlson Daniel <daniel.c.carlson at gmail.com>
> wrote:
>
> I just tested to run a cmake script with the -P option and the environment
> variable is still cleared when the script terminates...
>
> A nice solution to my problem would be to simply extend the set-command
> with an option like:
>
> set(ENV_KEEP{VAR} some_info)
>
> which means that the environment variable VAR will be set to 'some_info'
> and will NOT will be cleared when the script is terminated. What do you
> think about this? would this be possible?
>
> //Daniel
>
> 2009/3/29 Carlson Daniel < <daniel.c.carlson at gmail.com>
> daniel.c.carlson at gmail.com>
>
>> Thanks, but I do not think this is what I want. set($ENV{VAR} "some_data")
>> in a cmake-script will set an enviroment variable AND delete it when the
>> script terminates. Is this not true when using -P? Do I actually need an
>> execute_process-command (or anything else) in my script that will set the
>> environment variable?
>>
>>
>> 2009/3/29 Philip Lowman < <philip at yhbt.com>philip at yhbt.com>
>>
>> On Sun, Mar 29, 2009 at 9:04 AM, Carlson Daniel <<daniel.c.carlson at gmail.com>
>>> daniel.c.carlson at gmail.com> wrote:
>>>
>>>> Hello and sorry for my late response!
>>>>
>>>> I can not get this to work. When i execute the command COMMAND
>>>> ${CMAKE_COMMAND} -E ${template.cmake}
>>>>   I get an error saying something like:
>>>
>>>
>>> I believe there was a minor typo in the post.  The flag you probably want
>>> is "-P" which is "process script mode".
>>>
>>> <http://www.cmake.org/cmake/help/cmake2.6docs.html#section_Usage>
>>> http://www.cmake.org/cmake/help/cmake2.6docs.html#section_Usage
>>>
>>> --
>>> Philip Lowman
>>>
>>
>>
>
> _______________________________________________
> 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
>



-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090329/859ba6d5/attachment.htm>


More information about the CMake mailing list