PDA

View Full Version : QMake, partitioning, and duplicate targets



dhjdhj
1st August 2009, 18:04
New to Qt (but loving it) and trying to build up our own libraries for some products.

I was hoping to be able to nest .PRI files so that each of them would explicitly include other .PRI files whose headers/sources are needed. That way, the main .PRO file would not have to "know" about dependent .PRI files. Suppose for example my main project requires the use of a class defined in foo.h/foo.cpp. The main .PRO file should include only foo.pri in it.

Now suppose that the class defined in foo needs some dependant class defined in bar. The foo.pri file could include bar.pri (representing bar.h/bar/cpp) and life would be wonderful. This seems to work fine.

However, now suppose that the main .PRO wants both foo and bar and is not aware that foo already has bar as a dependency (and the user of the main program should NOT have to be aware of that dependency).

The main .PRO file will include both foo.pri and bar.pri.

But when I try this, I have found that the makefile has (among other things) the target bar.o defined twice, leading to duplicate symbols in the link process.

I thought I could write all the pri files using a similar wrapper as is used to prevent H files from being included more than once. Example:

#bar.pri
!contains(HEADERS, bar.h)
{
HEADERS += bar.h
SOURCES += bar.cpp
}


#foo.pri
!contains(HEADERS, foo.h)
{
include(bar.pri)
HEADERS += foo.h
SOURCES += foo.cpp
}


However, I have found that this does not seem to work and the targets continue to be duplicated.

Anyone know the right way to handle this?

THanks,

David

dhjdhj
1st August 2009, 18:41
Sigh ---- i just figured out (by accident) that the solution is to put the left curly brace on the same line as the conditional.
Since I don't generally write my code that way (I don't understand why anyone does, actually), it didn't occur to me that this would be a syntax issue.

So, for others who may run into this --- instead of writing

!contains(HEADERS, bar.h)
{
}

you have to write

!contains(HEADERS, bar.h){
}



Yuk!

ktk
3rd August 2009, 18:55
...

HEADERS += bar.h
SOURCES += bar.cpp

However, I have found that this does not seem to work and the targets continue to be duplicated.

Anyone know the right way to handle this?

Try HEADERS *= bar.h and SOURCES *= bar.cpp

dhjdhj
3rd August 2009, 19:28
Good to know about that as an alternative ---

Thank you