title: Qt resources files with CMake and AUTORCC
body: <p><strong>Solution</strong>:</p>
  
  <p>Add resource files in the <code>add_executable()</code> statement</p>
  
  <h1>Problem</h1>
  
  <p>(not in the <code>add_library()</code>)</p>
  
  <p>Fail to set main window icon.</p>
  
  <p><em>Notes</em>:</p>
  
  <ul>
  <li><p>When I don't use <code>AUTORCC</code> I run into some compilation problems:
  <code>QtCore/qglobal.h: no such file or directory</code>. But, I do prefer AUTORCC as a more modern CMake approach.</p></li>
  <li><p>Without the AUTORCC (different CMakeLists.txt than the provided) and Qt-4.6.2 the current code worked.
  different CMakeLists.txt)</p></li>
  </ul>
  
  <h2>Code</h2>
  
  <p>This is a minimized code of my project. Tree:</p>
  
  <pre><code>|- CMakeLists.txt
  |- main_window.hpp
  |- main_window.cpp
  |- main.cpp
  |- resources
     | - resources.qrc
     | - images
         | - logo.png
  </code></pre>
  
  <p><em>main_window.cpp</em></p>
  
  <pre><code>#ifndef MAINWINDOW_HPP
  #define MAINWINDOW_HPP
  
  #include &lt;QMainWindow&gt;
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  public:
      MainWindow();
  };
  
  #endif
  </code></pre>
  
  <p><em>main_window.cpp</em></p>
  
  <pre><code>#include "main_window.hpp"
  
  MainWindow::MainWindow()
  {
      // i tried ":/images.png", ":/resources/images/logo.png", ":/logo.png"
      setWindowIcon(QIcon(":images/logo.png"));    
  }
  </code></pre>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "main_window.hpp"
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      app.setOrganizationName("Organization");
      app.setApplicationName("Application Example");
      MainWindow mainWin;
      mainWin.show();
  
      return app.exec();
  </code></pre>
  
  <p>}</p>
  
  <p><em>CMakeLists.txt</em>.</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.1)
  
  project(qt_project)
  
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_AUTORCC ON)
  find_package(Qt4 4.6 REQUIRED)
  
  set(QT_USE_QTGUI TRUE)
  set(QT_USE_QTXML TRUE)
  
  include(${QT_USE_FILE})
  add_definitions(${QT_DEFINITIONS})
  
  // NOTE: it would be more convenient to be able to add the
  // resource file here upon the creation of the library
  add_library(mylib main_window.cpp)
  
  // SOLVED
  // BEFORE: add_executable(qt_test main.cpp)
  add_executable(qt_test main.cpp resources/resources.qrc)
  
  target_link_libraries(qt_test
      mylib
      ${QT_LIBRARIES}
  )
  </code></pre>
  
  <p><em>resources/resources.qrc</em></p>
  
  <pre><code>&lt;!DOCTYPE RCC&gt;&lt;RCC version="1.0"&gt;
      &lt;qresource&gt;
          &lt;file&gt;images/logo.png&lt;/file&gt;
      &lt;/qresource&gt;
  &lt;/RCC&gt;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>This is the generated <code>qrc_resources.cxx</code></p>
  
  <pre><code>#include &lt;QtCore/qglobal.h&gt;
  
  static const unsigned char qt_resource_data[] = {
    // /users/ddakop/dev/misc/qt/resources/images/logo.png
    // ... removed hex data
  };
  
  static const unsigned char qt_resource_name[] = {
    // images
    // ... removed hex data
      // logo.png
    // ... removed hex data
  
  };
  
  static const unsigned char qt_resource_struct[] = {
    // :
    0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
    // :/images
    0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
    // :/images/logo.png
    0x0,0x0,0x0,0x12,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
  
  };
  
  QT_BEGIN_NAMESPACE
  
  extern Q_CORE_EXPORT bool qRegisterResourceData
      (int, const unsigned char *, const unsigned char *, const unsigned char *);
  
  extern Q_CORE_EXPORT bool qUnregisterResourceData
      (int, const unsigned char *, const unsigned char *, const unsigned char *);
  
  QT_END_NAMESPACE
  
  
  int QT_MANGLE_NAMESPACE(qInitResources_resources)()
  {
      QT_PREPEND_NAMESPACE(qRegisterResourceData)
          (0x01, qt_resource_struct, qt_resource_name, qt_resource_data);
      return 1;
  }
  
  Q_CONSTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qInitResources_resources))
  
  int QT_MANGLE_NAMESPACE(qCleanupResources_resources)()
  {
      QT_PREPEND_NAMESPACE(qUnregisterResourceData)
         (0x01, qt_resource_struct, qt_resource_name, qt_resource_data);
      return 1;
  }
  
  Q_DESTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qCleanupResources_resources))
  </code></pre>
  
  <h1>System</h1>
  
  <p>CentOS-5, Qt-4.8.6, CMake-3.2.1, gcc-4.8.2</p>