tags:

views:

179

answers:

3

In order to keep my Qt project somewhat organized (using Qt Creator), I've got one .pro file and multiple .pri files. Just recently I added a class to one of my .pri files that has the same filename as a class that already existed in a separate .pri file.

The file structure and makefiles generated by qmake appear to be oblivious to the filename collision that ensues. The generated moc_* files all get thrown into the same subdirectory (either release or debug, depending) and one ends up overwriting the other. When I try to make the project, I get several warnings that look like this:

Makefile.Release:318: warning: overriding commands for target `release/moc_file.cpp`

And the project fails to link.

Here is a simple example of what I'm talking about.

Directory structure:

+ project_dir
| + subdir1
| | - file.h
| | - file.cpp
| + subdir2
| | - file.h
| | - file.cpp
| - main.cpp
| - project.pro
| - subdir1.pri
| - subdir2.pri

Contents of project.pro:

TARGET = project
TEMPLATE = app
include(subdir1.pri)
include(subdir2.pri)
SOURCES += main.cpp

Contents of subdir1.pri:

HEADERS += subdir1/file.h
SOURCES += subdir1/file.cpp

Contents of subdir2.pri:

HEADERS += subdir2/file.h
SOURCES += subdir2/file.cpp

Is there a way to tell qmake to generate a system that puts the moc_* files from separate .pri files into separate subdirectories?

+3  A: 

Best thing to do is to make sure that all files have a unique name. There are other tools besides qmake which will also break when you try to do what you're doing; you also potentially make it confusing for yourself (e.g. understanding what #include "file.h" does is more difficult).

Intransigent Parsnip
I don't necessarily agree with the confusion argument as my include statements would generally be of the form:#include "subdir1/file.h"Nontheless, you seem to be correct. Unique filenames seem to be the only way to go here.
Skinniest Man
I believe the moc files and the object files will not collide now if you have followed mine.. As opposed to your comment though :) Correct me if mine is wrong..
liaK
+2  A: 

In subdir1.pri try appending

MOC_DIR = "subdir1/MOCFiles"

Also for subdir2.pri give

MOC_DIR = "subdir2/MOCFiles"

It isn't tested. Just check it out. Hope it will work.

Edit 1 : Where MOCFiles is your desired folder for your moc files to get into.

Edit 2 : I just stopped mentioning with the MOC files directory since that has been asked specifically in the question. But additionally you may also have to add the following to each of the pri files. (Make sure that the folders are different for different *.pri files)

RCC_DIR = "subdir1/RCCFiles"
UI_DIR = "subdir1/UICFiles"
OBJECTS_DIR = "subdir1/ObjFiles"

I believe having multiple pri files can work without collisions by having the same file names. Since you have accepted an answer (which states it is not possible), make the above changes and give a try. Do let know if it isn't working.

liaK
No luck. The moc files are not colliding with each other now, but the object (.o) files are. Alas.
Skinniest Man
Try giving OBJECTS_DIR = "subdir2/ObjFiles"
liaK
A: 

I have tried this before. The short answer is to name them differently somehow. Another answer would be to treat each subdirectory as a separate library, with its own .pro file, and use a subdirs type to compile all the library directories.

If you really want to investigate a full answer, you can specify the tool to be used for moc. In this situation, you might be able to mangle the name so that a slightly different name is used for the two different files. However, you would then also need to make sure each differently-named file is added to the list of files to compile and link, and the originally-named moc file is not (or your build will fail).

Caleb Huitt - cjhuitt