[CMake] How to embed Qt resources using CMake

Pau Garcia i Quiles pgquiles at elpauer.org
Mon Jul 8 13:19:54 EDT 2013


Hello,

How do you call invoke CMakeLists1.txt and CMakeLists2.txt?

If you want to keep separate CMakeLists.txt, I would do something like this:

main/
CMakeLists.txt
-- resources/
-- -- pixmaps/
-- CMakeLists1.txt
-- icons.qrc
exe/
-- CMakeLists2.txt
-- main.cpp

Where CMakeLists.txt is something like this:

project(blah)

find_package(Qt4 REQUIRED)
include(${QT4_USE_FILE})

add_subdirectory(resources)
add_subdirectory(exe)

Then CMakeLists1.txt is something like this:

qt4_add_resources(lib_resources ${blah_SOURCE_DIR}/resources/icons.qrc)

(strictly speaking, the you don't need ${blah_SOURCE_DIR}/resources, but I
like to have full paths for things that may move around)

And CMakeLists2.txt would be something like this:

add_library(mylib ${lib_resources} ${other_sources})
target_link_libraries(mylib ${QT4_LIBRARIES})

But now you probably have a scoping problem with the variable
lib_resources, you may need to promote it to the parent scope.

Do you really require separate CMakeLists.txt? I only do that for complex
projects. If your project is not that involved, I think it's easier if you
add everything in one CMakeLists.txt in the root folder and you are done.


On Mon, Jul 8, 2013 at 6:59 PM, Júlio Hoffimann
<julio.hoffimann at gmail.com>wrote:

> My CMakeLists.txt resides at the same directory as icons.qrc, but my main
> application is linked in a completely separate folder:
>
> main/
> -- resources/
> -- -- pixmaps/
> -- CMakeLists1.txt
> -- icons.qrc
> exe/
> -- CMakeLists2.txt
> -- main.cpp
>
> Is it okay? What should be the CMakeLists(1|2).txt in this case?
>
> Júlio.
>



-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130708/88c27c07/attachment.htm>


More information about the CMake mailing list