[CMake] How to test environment variable in IF command

2007-07-19 Thread Mike Talbot

Hi,

I'm trying to work out how to test for an environment variable in an IF 
command, the following doesn't work:


SET(ENV{FOO} ON)
MESSAGE(FOO = $ENV{FOO})# prints FOO = ON
IF(ENV{FOO})
 MESSAGE(FOO is set)
ENDIF(ENV{FOO})

Does anyone know what the right syntax for doing this is, please?

Thanks,
Mike

--
Mike Talbot
Core Petrel Architect (Abingdon)
Schlumberger
Lambourn Court, Wyndyke Furlong,
Abingdon Business Park, Abingdon,
Oxfordshire, OX14 1UJ, UK
Office: +44 (0)1235 543 488
Mobile: +44 (0)7790 382 746

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] How to test environment variable in IF command

2007-07-19 Thread David Cole

When dealing with ENV variable values, you should probably test their
contents with something like this:

IF($ENV{FOO} STREQUAL ON)
... ... ...
ENDIF($ENV{FOO} STREQUAL ON)

--- or ---

SET(myFOO $ENV{FOO})
IF(myFOO)
... ... ...
ENDIF(myFOO)


HTH,
David


On 7/19/07, Mike Talbot [EMAIL PROTECTED] wrote:


Hi,

I'm trying to work out how to test for an environment variable in an IF
command, the following doesn't work:

SET(ENV{FOO} ON)
MESSAGE(FOO = $ENV{FOO})# prints FOO = ON
IF(ENV{FOO})
  MESSAGE(FOO is set)
ENDIF(ENV{FOO})

Does anyone know what the right syntax for doing this is, please?

Thanks,
Mike

--
Mike Talbot
Core Petrel Architect (Abingdon)
Schlumberger
Lambourn Court, Wyndyke Furlong,
Abingdon Business Park, Abingdon,
Oxfordshire, OX14 1UJ, UK
Office: +44 (0)1235 543 488
Mobile: +44 (0)7790 382 746

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to test environment variable in IF command

2007-07-19 Thread Mike Talbot

Ok - thanks, that works.

David Cole wrote:
When dealing with ENV variable values, you should probably test their 
contents with something like this:


IF($ENV{FOO} STREQUAL ON)
... ... ...
ENDIF($ENV{FOO} STREQUAL ON)

 --- or ---

SET(myFOO $ENV{FOO})
IF(myFOO)
... ... ...
ENDIF(myFOO)


HTH,
David


On 7/19/07, *Mike Talbot* [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


Hi,

I'm trying to work out how to test for an environment variable in
an IF
command, the following doesn't work:

SET(ENV{FOO} ON)
MESSAGE(FOO = $ENV{FOO})# prints FOO = ON
IF(ENV{FOO})
  MESSAGE(FOO is set)
ENDIF(ENV{FOO})

Does anyone know what the right syntax for doing this is, please?

Thanks,
Mike

___
CMake mailing list
CMake@cmake.org mailto:CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake




___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to test environment variable in IF command

2007-07-19 Thread Philippe Fremy

Mike Talbot wrote:
 Hi,
 
 I'm trying to work out how to test for an environment variable in an IF
 command, the following doesn't work:
 
 SET(ENV{FOO} ON)
 MESSAGE(FOO = $ENV{FOO})# prints FOO = ON
 IF(ENV{FOO})
  MESSAGE(FOO is set)
 ENDIF(ENV{FOO})
 
 Does anyone know what the right syntax for doing this is, please?
 
 Thanks,
 Mike
 


I can't tell you why because the syntax rules of CMake are still obscure
to me but this works:

SET(ENV{FOO} ON)
MESSAGE(FOO = $ENV{FOO})# prints FOO = ON
SET( A $ENV{FOO} )
MESSAGE(A = ${A})
IF(A)
 MESSAGE(FOO is set)
ELSE(A)
 MESSAGE(FOO is not set)
ENDIF(A)

EXECUTE_PROCESS( COMMAND bash -c 'echo EDITOR=$EDITOR' )
EXECUTE_PROCESS( COMMAND bash -c 'echo FOO=$FOO' )


___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake