[CMake] $ENV{HOSTNAME}

Salvatore Iovene salvatore.iovene+cmake at googlemail.com
Wed Nov 21 09:27:53 EST 2007


On Nov 21, 2007 4:02 PM, Salvatore Iovene
<salvatore.iovene+cmake at googlemail.com> wrote:
>
> > On Nov 21, 2007 3:56 PM, Gonzalo Garramuño <ggarra at advancedsl.com.ar> wrote:
> > > Salvatore Iovene wrote:
> > > >
> > > > A bug? Thanks.
> > > >
> > >
> > > Nope.
> > >
> > > $ echo $HOSTNAME
> > > aura1
> > >
> > > $ sh -c "echo \$HOSTNAME"
> > >
> > > $ bash -c "echo \$HOSTNAME"
> > > aura1
> > >
> > > Basically, HOSTNAME is a variable that is set by some shells like bash
> > > only, but cmake for speed and consistency runs commands using the most
> > > basic unix shell (ie. sh), which does not set that variable by default.
> >
> > Thanks. How can I work this around? I really need to get the HOSTNAME in a
> > shell-independent way. Maybe there's a way to execute the `hostname`
> > command?
>
> Besides:
>
> siovene at sd024:/work/trunk/libraries$ sh -c "echo \$HOSTNAME"
> sd024
> siovene at sd024:/work/trunk/libraries$ /bin/sh -c "echo \$HOSTNAME"
> sd024
> siovene at sd024:/work/trunk/libraries$ ls -lh /bin/sh
> lrwxrwxrwx 1 root root 4 2007-11-13 16:18 /bin/sh -> bash
>
> So sh is actually bash, on my machine.

Ok, I see now. HOSTNAME is a shell variable, but not an environment
variable. Check this thread here:

http://lists.freebsd.org/pipermail/freebsd-questions/2004-July/052424.html

So, is there another way I could get the hostname in CMake?
Thanks.


-- 
Salvatore Iovene
http://www.iovene.com/
Key Fingerprint: 5647 944D D5AD 2E87 00B4  7D54 2864 359D FF20 16D8


More information about the CMake mailing list