[CMake] QT4_WRAP_UI, INCLUDE_DIRECTORIES and source tree structure

Christiaan Putter ceputter at googlemail.com
Tue Nov 6 12:20:26 EST 2007


Hi there guys,

First off I'm new to cmake (and c++ and qt too :-) ), so please bear this in
mind.

I'm having some trouble with my source tree layout, and don't know if I'm
doing this right.

I'll first explain what I've done, and then tell you what's not working.

My source tree:

project
-->build
-->source
-->-->app
-->-->-->main.cpp
-->-->--> CMakeLists.txt
-->-->gui
-->-->-->mainwindow.h
-->-->-->mainwindow.cpp
-->-->-->mainwindow.ui
-->-->-->CMakeLists.txt
-->-->CMakeLists.txt
-->CMakeLists.txt

Very straight forward, and logical way to layout my source files.  I
thought.

Now, all the open source projects using cmake I found on the net mostly
throw all their source files into a single directory, so I couldn't find a
proper example for what I want really.

The way I thought to do this is to build libraries from some stuff (gui in
this case), and then link this into the executable in app.

This does work, but maybe there's a more standard way to use cmake on such a
source tree?

The actual problem I'm having is with includes:

ui_*.h files get generated in the gui folder (the one in the build tree of
course), and the gui library gets built without problems.

The problem though is when including mainwindow.h from main.cpp in the app
folder.  Because mainwindow.h includes ui_mainwindow.h generated by
QT4_WRAP_UI.

I do have,

INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )

in the CMakeLists.txt file building the gui library.  And, like I said, the
gui library gets built fine, so it's picking up the ui_mainwindow.h which is
in the build tree and not in the source tree.

But, when building the app executable, this isn't in the includes any more
and the compiler says it can't find ui_mainwindow.h  (it's only looking in
the source tree I guess).

I can solve this by adding,

INCLUDE_DIRECTORIES(${project_BINARY_DIR}/source/gui)

in the CMakeLists.txt file in the app folder, thus telling it again to go
look for the header in the build tree.  Even though I already included it
earlier on when building the gui library, CMake seems to forget this.


Can some please explain to me what is the proper way of using cmake (with
Qt4) on more complex source trees, and why my way isn't working properly.

Hope you're all having a great day.

Regards,
cputter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071106/4301791f/attachment.html


More information about the CMake mailing list