tags:

views:

432

answers:

2

Hi,

I am starting a multiplatform (Win Xp, Linux) qt project. I want to use an out of source build so my directory structure is as followed:

project/
  CMakeLists.txt   (global CMake file, includes other CMakeLists)
  build/           (my build directory)
  libA/
    CMakeLists.txt
  mystuff/
    subprojectA/
      CMakeLists.txt
    subprojectB/
      CMakeLists.txt

So when I use that on Windows with the Visual Studio generator everything builds fine. If I use the same structure and CMakeLists on Linux or under Windows with the MinGW generator I get compile errors because the qt generated files (through moc and uic) lying under the build directory cannot find my header files in my subprojects. Some of the qt generated header/source files are dependent on my header/source files because I use promoted widgets in my .ui files which point to the implementation in my source. Again under Visual Studio / NMake everything compiles fine.

As a workaround I can use an in source build which runs fine or I can add the following on the global CMakeLists.txt:

include_directories(
  mystuff/subprojectA
  mystuff/subprojectB
)

But what is the right solution? Thank you very much!!

+2  A: 

I have a similar problem, with includes for out of source builds on unix (although I am not using QT), and in each effected projected I added:

include_directories( . )

Not the most elegant but I worked for me.

iain
hey cool that works for me! not the perfect answer but a good workaround, thank you!
yoursort
+1  A: 

In a project I'm working on I use this statement to handle includes in my CMakeLists.txt :

 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${OPENSSL_INCLUDE_DIR})

The keyword is ${CMAKE_CURRENT_BINARY_DIR}, hope that helps.

Side note, if you are using gcc 4.4.x with exceptions enabled, you might want to use this so it wouldn't link against libgcc_s_sjlj-1.dll on windows.

 SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-static-libgcc")
OneOfOne
No, I do not want to include my moc files(which indeed I do already) and so on, but my moc generated files need to include some files (of my subprojects) for themselves because I use promoted widgets in the .ui files. So the answer from iain solves my problem.
yoursort