title: How to Integrate Qt4 qm files into binary using cmake and QRC?
body: <p>I have a Qt4 CMake project and I'd like to integrate the QM files for i18n into the output binary. These are the rules I have so far for generating the TS and QM files:</p>
  
  <pre><code>set(myapp_TRANSLATIONS
      i18n/myapp_de.ts
  )
  
  set(FILES_TO_TRANSLATE
      ${myapp_SRCS}
      ${myapp_MOC_HDRS}
  )
  
  QT4_CREATE_TRANSLATION(QM_FILES ${FILES_TO_TRANSLATE} ${myapp_TRANSLATIONS})
  QT4_ADD_TRANSLATION(QM ${myapp_TRANSLATIONS})
  </code></pre>
  
  <p>I tried the following to add the QM files to the executable:</p>
  
  <pre><code>add_executable(myapp ${myapp_SRCS} ${myapp_MOC_SRCS} ${myapp_RCC_SRCS} ${QM})
  </code></pre>
  
  <p>This is the initialization from main.cpp:</p>
  
  <pre><code>QTranslator qtTranslator;
  qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
  app.installTranslator(&amp;qtTranslator);
  
  QTranslator appTranslator;
  appTranslator.load("myapp_" + QLocale::system().name());
  app.installTranslator(&amp;appTranslator);
  </code></pre>
  
  <p>However, <code>strings mypp</code> shows that the translations are not going into the binary.</p>
  
  <p><strong>Update:</strong> I added each qm file to a <code>i18n/translations.qrc</code>:</p>
  
  <pre><code>&lt;!DOCTYPE RCC&gt;&lt;RCC version="1.0"&gt;
    &lt;qresource prefix="/resources"&gt;
      &lt;file&gt;myapp_de.qm&lt;/file&gt;
      &lt;file&gt;  ...   .qm&lt;/file&gt;
    &lt;/qresource&gt;
  &lt;/RCC&gt;
  </code></pre>
  
  <p>and using</p>
  
  <pre><code>QT4_ADD_RESOURCES(myapp_QM_RCC_SRCS i18n/translations.qrc)
  </code></pre>
  
  <p>and adding <code>myapp_QM_RCC_SRCS</code> to the executable dependencies.</p>
  
  <p>But this fails during build time thanks to the fact that CMake does a shadow build (building outside the source dir) but parses the QRC files for dependencies expecting the referenced files relative to the QRC file (nice feature but there's no make rule how to build the QM file at that location). The QM files are in <code>${CMAKE_CURRENT_BINARY_DIR}</code> (where they belong using shadow building) but expects it in <code>${CMAKE_CURRENT_SOURCE_DIR}</code> (where non-generated files should be - so both locations would be correct, depending on situation).</p>