[CMake] How to embed Qt resources using CMake

Bogdan Cristea cristeab at gmail.com
Mon Jul 8 12:25:10 EDT 2013


The paths should be relative to the folder where your qrc file reside. 
Then you can use

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


On 08.07.2013 18:17, Júlio Hoffimann wrote:
> 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.
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130708/8e9fa016/attachment-0001.htm>


More information about the CMake mailing list