Results 1 to 4 of 4

Thread: QMake, partitioning, and duplicate targets

  1. #1
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QMake, partitioning, and duplicate targets

    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

  2. #2
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMake, partitioning, and duplicate targets

    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!

  3. #3
    Join Date
    May 2008
    Posts
    155
    Thanked 15 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMake, partitioning, and duplicate targets

    Quote Originally Posted by dhjdhj View Post
    ...

    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

  4. #4
    Join Date
    Jul 2009
    Posts
    41
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMake, partitioning, and duplicate targets

    Good to know about that as an alternative ---

    Thank you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.