title: Get cmake options from program
body: <p>How can I get CMake options used for building from within a program?</p>
  
  <p>E.g. I would like to use this:</p>
  
  <pre><code>int main()
  {
      std::cout &lt;&lt; "Build options: " &lt;&lt; BUILD_OPTIONS &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><code>BUILD_OPTIONS</code> would contain a string with all options passed to <code>cmake</code>, like:</p>
  
  <pre><code>cmake -DOPT1 -DOPT3
  </code></pre>
  
  <p>with <code>CMakeLists.txt</code> defined as follows:</p>
  
  <pre><code>option(OPT1 "option 1" OFF)
  option(OPT2 "option 2" OFF)
  option(OPT3 "option 3" OFF)
  </code></pre>
  
  <p>The desired output of such program:</p>
  
  <pre><code>Build options: OPT1=ON OPT3=ON
  </code></pre>
  
  <p>(<code>OPT2</code> skipped, as it is not defined explicitly and equal to default value)</p>