Hi there guys,<br><br>First off I'm new to cmake (and c++ and qt too :-) ), so please bear this in mind.<br><br>I'm having some trouble with my source tree layout, and don't know if I'm doing this right.<br>
<br>I'll first explain what I've done, and then tell you what's not working.<br><br>My source tree:<br><br>project<br>-->build<br>-->source<br>-->-->app<br>-->-->-->main.cpp<br>-->-->-->
CMakeLists.txt<br>-->-->gui<br>-->-->-->mainwindow.h<br>-->-->-->mainwindow.cpp<br>-->-->-->mainwindow.ui<br>-->-->-->CMakeLists.txt<br>-->-->CMakeLists.txt<br>-->CMakeLists.txt
<br><br>Very straight forward, and logical way to layout my source files. I thought.<br><br>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.
<br><br>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.<br><br>This does work, but maybe there's a more standard way to use cmake on such a source tree?
<br><br>The actual problem I'm having is with includes:<br><br>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.<br><br>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.<br><br>I do have,<br><br>INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )<br><br>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.<br><br>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).
<br><br>I can solve this by adding,<br><br>INCLUDE_DIRECTORIES(${project<div id="mb_0">_BINARY_DIR}/source/gui)<br><br>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.
<br><br><br>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.<br><br>Hope you're all having a great day.<br><br>Regards,
<br>cputter</div>