[CMake] how to check if ENV exists

David Cole david.cole at kitware.com
Fri Nov 16 10:03:44 EST 2007


Unfortunately, there is no easy way (perhaps no way at all?) to tell the
difference between "empty string value of an env var" and "env var does not
exist".

But you can do this:

IF("$ENV{TESTVAR}" STREQUAL "")
  # code to handle empty/non-existent env var
ELSE("$ENV{TESTVAR}" STREQUAL "")
  # code that uses non-empty "$ENV{TESTVAR}"
ENDIF("$ENV{TESTVAR}" STREQUAL "")


HTH,
David


On 11/16/07, Sören Freudiger <muffmolch at gmx.de> wrote:
>
> Just a short question.
>
> How to check if an environment variable exist?
>
> Something like:
> IF( ENV{TESTVAR} )
> ...
>
> Because elsewise I get errors at $ENV{TESTVAR} if TESTVAR doesn't exist...
>
> Best,
> SirAnn
>
>
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071116/02d01d4e/attachment-0001.html


More information about the CMake mailing list