[CMake] QT4_WRAP_UI, INCLUDE_DIRECTORIES and source tree structure

Alexander Neundorf a.neundorf-work at gmx.net
Tue Nov 6 18:35:35 EST 2007


On Tuesday 06 November 2007, Christiaan Putter wrote:
> 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)

Yes, I think you have to do that.
How do you include the generated file, using "" or <> ?

Alex


More information about the CMake mailing list