title: CMake Custom Command Depending On Variable
body: <p>Part of my build process requires passing in a variable to a script to generate some source files. It looks something like this:</p>
  
  <pre><code>    add_custom_command(OUTPUT
          rebuild_files
          COMMAND ${CMAKE_COMMAND} -E echo
          COMMENT "Force rebuild of generated files"
      )
  
      add_custom_command(OUTPUT "File.c" "File.h"
          COMMAND ruby generate_files.rb ${OPTIONS_LIST}
          COMMENT "Generate files"
          DEPENDS rebuild_files
      )
  </code></pre>
  
  <p>Of course, this runs on every compilation, which isn't needed. The <code>OPTIONS_LIST</code> is set up at configuration time, so it could be cached.</p>
  
  <p>Is there a mechanism to make a custom command dependent on a variable? The ultimate goal is to have this only compile if:</p>
  
  <ol>
  <li><code>OPTIONS_LIST</code> changes.</li>
  <li><code>File.c</code> or <code>File.h</code> do not exist.</li>
  </ol>