title: How to reuse code in CMake
body: <p>I've got the following piece of code which gets the current system IP and stores it in the <code>SERVER_IP</code> variable:</p>
  
  <pre><code>EXECUTE_PROCESS(
      COMMAND ip route get 8.8.8.8
      COMMAND awk "NR==1 {print $NF}"
      OUTPUT_VARIABLE SERVER_IP
      OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  </code></pre>
  
  <p>I need to use this IP several places in my <code>CMakeLists.txt</code> file hierarchy. What's the best approach to reuse this code? My first thought is to make it a function like <code>function(GetIP)</code>, but I am not sure where to put this function to make it visible to all CMakeLists.txt file.</p>