The CMake SITE_NAME command does this in a shell / platform independent way...<br><br><div>See output of "cmake --help-command SITE_NAME"</div><div><br class="webkit-block-placeholder"></div><div><br><div><span class="gmail_quote">
On 11/21/07, <b class="gmail_sendername">James Bigler</b> <<a href="mailto:bigler@cs.utah.edu">bigler@cs.utah.edu</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br>Salvatore Iovene wrote:<br>> On Nov 21, 2007 4:46 PM, James Bigler <<a href="mailto:bigler@cs.utah.edu">bigler@cs.utah.edu</a>> wrote:<br>>>>>> shell-independent way. Maybe there's a way to execute the `hostname`
<br>>>>>> command?<br>>>> Ok, I see now. HOSTNAME is a shell variable, but not an environment<br>>>> variable. Check this thread here:<br>>>><br>>>> <a href="http://lists.freebsd.org/pipermail/freebsd-questions/2004-July/052424.html">
http://lists.freebsd.org/pipermail/freebsd-questions/2004-July/052424.html</a><br>>>><br>>>> So, is there another way I could get the hostname in CMake?<br>>> I would do what was suggested and call 'hostname' with EXECUTE_PROCESS()
<br>>> (see cmake documentation).<br>><br>> Thanks, that works, but the OUTPUT_VARIABLE has a trailing \n. How can<br>> I get rid of it?<br><br>Try using a string replacement or the OUTPUT_STRIP_TRAILING_WHITESPACE
<br>argument to EXECUTE_PROCESS:<br><br>################################################3<br>### Run with cmake -P hostname.cmake<br><br>EXECUTE_PROCESS( COMMAND hostname<br> OUTPUT_VARIABLE myhostname<br>
)<br><br>MESSAGE("myhostname = \"${myhostname}\"")<br><br>STRING(REPLACE "\n" "" new_hostname ${myhostname})<br><br>MESSAGE("new_hostname = \"${new_hostname}\"")
<br><br># Or use the handy dandy OUTPUT_STRIP_TRAILING_WHITESPACE argument<br># to EXECUTE_PROCESS<br>EXECUTE_PROCESS( COMMAND hostname<br> OUTPUT_VARIABLE myhostname2<br> OUTPUT_STRIP_TRAILING_WHITESPACE
<br> )<br><br>MESSAGE("myhostname2 = \"${myhostname2}\"")<br><br>####################################################<br><br>James<br>_______________________________________________<br>
CMake mailing list<br><a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br><a href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br> </div>