[CMake] Test if ENV${VAR} is set

Bogdan Cristea cristeab at gmail.com
Fri Sep 14 16:43:52 EDT 2012


On Friday 14 September 2012 16:26:10 you wrote:
> On Fri, Sep 14, 2012 at 4:17 PM, Bogdan Cristea <cristeab at gmail.com> wrote:
> > On Friday 14 September 2012 16:13:16 Davis Ford wrote:
> >> if("$ENV{FOO_HOME}" MATCHES "")
> >> 
> >>    message("You must set FOO_HOME")
> >>    return()
> >> 
> >> endif()
> > 
> > Try something like this
> > 
> > if(NOT ENV{FOO_HOME})
> > message("etc")
> > endif()
> > 
> > --
> > Bogdan
> > --
> > 
> > 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
> 
> I would use the double quotes like you had originally, but use
> STREQUAL instead of MATCHES. Or use MATCHES "^$" to match ONLY the
> explicitly empty string, because MATCHES "" basically matches
> everything because everything "contains" the empty string...
> 
> HTH,
> David

I have tested and this should work

set(VAR $ENV{FOO_VAR})
if (NOT VAR)
  message("Cannot find FOO_VAR")
endif()

For some reason, when I use directly
if (NOT ENV{FOO_VAR})
does not seem to work.

-- 
Bogdan Cristea
Software Engineer
tel: +33 (0)6 21 64 15 81
      +33 (0)6 26 74 98 19
personal site: http://sites.google.com/site/cristeab/


More information about the CMake mailing list