[CMake] Reruning cmake and environment variables

elizabeta petreska elizabeta.petreska at gmail.com
Mon Nov 2 03:36:13 EST 2009


Thank you, it works.

On Sun, Nov 1, 2009 at 4:36 PM, Michael Wild <themiwi at gmail.com> wrote:

>
> On 1. Nov, 2009, at 16:27 , elizabeta petreska wrote:
>
>  Hello
>>
>> I am using Windows ansd Cmake 2.6. I am invoking CMake from command window
>> which has set some environment  variables. The environment  variables are
>> visible only the during the lifetime of the command window.
>> I am using the environment  variables in many places through my
>> cmakelists.txt , for example in INCLUDE_DIRECTORIES, LINK_LIBRARIES etc.
>> The
>> environment  variables are mainly set with file path strings.
>>
>> Problem :
>> When I am working in Visual Studio on my project, if my cmakelists.txt for
>> the project is changed, Cmake is rerun from Visual Studio.
>> Because  Cmake is run from Visual Studio , and not the shell where the
>> environment  variables are set , it can't recognize the environment
>> variables. How to overcome this ?
>> Thanks
>>
>
> Somewhere short after the PROJECT command, put something like this:
>
> foreach(_var VAR1 VAR2 VAR3 VAR4)
>  if(NOT DEFINED ${_var})
>    set(${_var} "$ENV{${_var}}" CACHE INTERNAL "This is my super variable
> ${_var}")
>  endif()
> endforeach()
>
> This will initialize internal cache variables with the values from the
> environment, and then in subsequent runs use the values from the cache.
>
>
> HTH
>
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091102/dea7b536/attachment.htm>


More information about the CMake mailing list