title: How to read a CMake Variable in C++ source code
body: <p>I'd like to store the version number of my library in just one place. So I have defined such a variable in the CMake-file:</p>
  
  <pre><code>    SET(LIBINTERFACE_VERSION 1 CACHE INTEGER "Version of libInterface")
  </code></pre>
  
  <p>With this definition I can generate a version.rc file according to Microsoft's definition, which I compile into the library and afterwards shows up correctly in the properties window of my dll-file.</p>
  
  <p>Now I'd like to use this CMake variable in my c++ source code too, but I actually don't get to a working solution. I've tried different things like this:</p>
  
  <pre><code>    #ifndef VERSION_LIBINTERFACE
      #  define VERSION_LIBINTERFACE @LIBINTERFACE_VERSION@
      #endif
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>    unsigned int getLibInterfaceVersion()
      {
          return @LIBINTERFACE_VERSION@;
      }
  </code></pre>
  
  <p>But the compiler won't accept anything. Since my researches in the CMake-Documentation didn't get any results, I hope that someone could give me the essential advice.</p>
  
  <p>Thanks in advance.</p>