title: How do I build a Win32 app with a resource file using cmake and MinGW?
body: <p>In theory, it's very easy to build a Win32 app with a resource file using cmake. In an <code>add_executable</code> command, a resource file can be listed as easily as a C or C++ source file. There is a known bug, however, when building using MinGW tools.</p>
  
  <p>I found a workaround, which is to include the following in CMakeFiles.txt...</p>
  
  <pre><code>if(MINGW)
    set(CMAKE_RC_COMPILER_INIT windres)
    ENABLE_LANGUAGE(RC)
    SET(CMAKE_RC_COMPILE_OBJECT
        "&lt;CMAKE_RC_COMPILER&gt; &lt;FLAGS&gt; &lt;DEFINES&gt; -o &lt;OBJECT&gt; &lt;SOURCE&gt;")
  endif(MINGW)
  </code></pre>
  
  <p>Unfortunately, this doesn't seem to work. What seems to happen is that <code>windres</code> generates a <code>&lt;whatever&gt;.rc.res</code> file which <code>ld</code> doesn't understand.</p>
  
  <p>In my searches, I've developed a strong suspicion that Win32 support is seen as a very low priority, especially outside of Visual Studio. This is understandable, as Win32 obviously isn't as important as it once was. And of course Visual Studio Express Editions are easily available for free.</p>
  
  <p>Even so, it would be convenient for me if I could use MinGW GCC for a few old Win32 apps I still use. If nothing else, I can get GCOV test coverage stats.</p>
  
  <p>Obviously if all else fails, I could always handle resource files using a custom build command. One issue is that I'm not familiar with either windres or ld, or how MinGW is meant to handle Win32 resource files. Another is that I don't really want to reinvent the wheel if someone already has a superior wheel they'd like to share with me.</p>
  
  <p>So that's basically it - how can I support building Win32 apps with resource files using cmake, and using MinGW (but not breaking support for Visual Studio)?</p>