[CMake] How to embed Qt resources using CMake

Júlio Hoffimann julio.hoffimann at gmail.com
Mon Jul 8 12:17:32 EDT 2013


Dear all,

I'm not that experienced with Qt, but I'm migrating an existing application
to use CMake as the build system. It all worked smoothly, except the icons
in the GUI aren't being shown.

Suppose I'm a directory named main/ that has a subdirectory named
resources/pixmaps:

main/
-- resources/
-- -- pixmaps/
-- -- -- icon1.png
-- -- -- icon2.png

My CMakeLists.txt resides at main/. I also have an icons.qrc with the
following content:

<RCC>
    <qresource prefix="/icons">
        <file>resources/pixmaps/icon1.png</file>
        <file>resources/pixmaps/icon2.png</file>
    </qresource></RCC>


I tried the following:

QT4_ADD_RESOURCES(lib_resources icons.qrc)
add_library(mylib ${lib_srcs} ${lib_resources})

Should I copy icons.qrc to the correspondent ${CMAKE_CURRENT_BINARY_DIR}?
The paths in icons.qrc should be relative to what?

I have tried put @CMAKE_CURRENT_SOURCE_DIR@ in the icons.qrc entries and
configure_file() it for getting absolute paths:

<RCC>
    <qresource prefix="/icons">
        <file alias="resources/pixmaps/icon1.png">@CMAKE_CURRENT_SOURCE_DIR@/resources/pixmaps/icon1.png</file>
        <file alias="resources/pixmaps/icon2.png">@CMAKE_CURRENT_SOURCE_DIR@/resources/pixmaps/icon2.png</file>
    </qresource></RCC>


but also didn't work.

I appreciate if you provide a minimal working example with best practices
regarding CMake parallel builds. Perhaps a hello world example with an icon
instead?

Best,
Júlio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130708/b689f935/attachment.htm>


More information about the CMake mailing list