[CMake] $ENV{HOSTNAME}

David Cole david.cole at kitware.com
Wed Nov 21 10:14:43 EST 2007


The CMake SITE_NAME command does this in a shell / platform independent
way...

See output of "cmake --help-command SITE_NAME"


On 11/21/07, James Bigler <bigler at cs.utah.edu> wrote:
>
>
>
> Salvatore Iovene wrote:
> > On Nov 21, 2007 4:46 PM, James Bigler <bigler at cs.utah.edu> wrote:
> >>>>> shell-independent way. Maybe there's a way to execute the `hostname`
> >>>>> command?
> >>> 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?
> >> I would do what was suggested and call 'hostname' with
> EXECUTE_PROCESS()
> >> (see cmake documentation).
> >
> > Thanks, that works, but the OUTPUT_VARIABLE has a trailing \n. How can
> > I get rid of it?
>
> Try using a string replacement or the OUTPUT_STRIP_TRAILING_WHITESPACE
> argument to EXECUTE_PROCESS:
>
> ################################################3
> ###  Run with cmake -P hostname.cmake
>
> EXECUTE_PROCESS( COMMAND hostname
>                   OUTPUT_VARIABLE myhostname
>                  )
>
> MESSAGE("myhostname = \"${myhostname}\"")
>
> STRING(REPLACE "\n" "" new_hostname ${myhostname})
>
> MESSAGE("new_hostname = \"${new_hostname}\"")
>
> # Or use the handy dandy OUTPUT_STRIP_TRAILING_WHITESPACE argument
> # to EXECUTE_PROCESS
> EXECUTE_PROCESS( COMMAND hostname
>                   OUTPUT_VARIABLE myhostname2
>                   OUTPUT_STRIP_TRAILING_WHITESPACE
>                  )
>
> MESSAGE("myhostname2 = \"${myhostname2}\"")
>
> ####################################################
>
> James
> _______________________________________________
> 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/20071121/6e49bf62/attachment.htm


More information about the CMake mailing list