The CMake SITE_NAME command does this in a shell / platform independent way...<br><br><div>See output of &quot;cmake --help-command SITE_NAME&quot;</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> &lt;<a href="mailto:bigler@cs.utah.edu">bigler@cs.utah.edu</a>&gt; 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>&gt; On Nov 21, 2007 4:46 PM, James Bigler &lt;<a href="mailto:bigler@cs.utah.edu">bigler@cs.utah.edu</a>&gt; wrote:<br>&gt;&gt;&gt;&gt;&gt; shell-independent way. Maybe there&#39;s a way to execute the `hostname`
<br>&gt;&gt;&gt;&gt;&gt; command?<br>&gt;&gt;&gt; Ok, I see now. HOSTNAME is a shell variable, but not an environment<br>&gt;&gt;&gt; variable. Check this thread here:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; <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>&gt;&gt;&gt;<br>&gt;&gt;&gt; So, is there another way I could get the hostname in CMake?<br>&gt;&gt; I would do what was suggested and call &#39;hostname&#39; with EXECUTE_PROCESS()
<br>&gt;&gt; (see cmake documentation).<br>&gt;<br>&gt; Thanks, that works, but the OUTPUT_VARIABLE has a trailing \n. How can<br>&gt; 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>###&nbsp;&nbsp;Run with cmake -P hostname.cmake<br><br>EXECUTE_PROCESS( COMMAND hostname<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT_VARIABLE myhostname<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br><br>MESSAGE(&quot;myhostname = \&quot;${myhostname}\&quot;&quot;)<br><br>STRING(REPLACE &quot;\n&quot; &quot;&quot; new_hostname ${myhostname})<br><br>MESSAGE(&quot;new_hostname = \&quot;${new_hostname}\&quot;&quot;)
<br><br># Or use the handy dandy OUTPUT_STRIP_TRAILING_WHITESPACE argument<br># to EXECUTE_PROCESS<br>EXECUTE_PROCESS( COMMAND hostname<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT_VARIABLE myhostname2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT_STRIP_TRAILING_WHITESPACE
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br><br>MESSAGE(&quot;myhostname2 = \&quot;${myhostname2}\&quot;&quot;)<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>&nbsp;</div>