[SOLVED] How can I test whether a .pri file has already been included

  • I have multiple subfolders of a project. Each of these subfolders contains a .pri file describing what files need to be included. There is some cross-referencing when a subfolder needs a component from another. A simple and silly description of this problem is as follows:

    in /root/sub0/sub0.pri:
    include( /root/sub1/sub1.pri )

    in /root/sub1/sub1.pri:
    include( /root/sub0/sub0.pri )

    in /root/root.pri
    include( /root/sub0/sub0.pri )
    include( /root/sub1/sub1.pri )

    When I compile this after running qmake, I get problems with:

    "overriding commands for target ------"

    and warnings about multiple definitions.

    Is there a way in a qmake project file to test if a .pri file has already been included somewhere else??

  • You can use same approach as in c/c++ headers. Defines. Just test for define and if not defined then define it and do stuff.

  • what is the syntax for that in a .pri file?

  • Thank you Denis. I took your advice and expanded it a bit. Here's the template that I used for protecting my .pri files from multiple inclusion:

    !contains( included_modules, $$PWD ) {
    included_modules += $$PWD
    message( "Including $$PWD" )

    .pri body

    HEADERS, SOURCES, QT *=, include(), etc...

    } else {
    message( "Skipping $$PWD: already included" )

    Thanks for the help

  • You are welcome. Please mark thread as [solved].

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.