qmake and 'include' function



  • Hi! I have a development directory structure more or less like this:

    /
    /common
    common.pro
    /a
    a.pro

    In 'a.pro' I want to include 'common.pro', and I want the paths referenced in common.pro be relative to 'a' directory.

    Does anyone know how to do it?

    Thanks!



  • Hi,
    just use
    include(../common/common.pro)

    in a,pro



  • Thanks for your answer.

    I tried that, but the relative paths in 'common.pro' stay relative to where 'common.pro' is, and not to where 'a.pro' is.



  • Sorry, misunderstood the question..

    In that case you can use the qmake-variable

    _PRO_FILE_PWD_
    

    using a test with some testfiles like this:

    test.pro:

    TEMPLATE        = subdirs 
    SUBDIRS         += a
    SUBDIRS         += common
    

    a/a.pro:

    message("pwd is $$_PRO_FILE_PWD_")
    include(../common/common.pro)
    

    common/common.pro:

    message("pwd in common is $$_PRO_FILE_PWD_")
    
    

    gives this result:

    d:\zw\qmaketest>qmake -r
    Reading D:/zw/qmaketest/a/a.pro
    Project MESSAGE: pwd is D:/zw/qmaketest/a
    Project MESSAGE: pwd in common is D:/zw/qmaketest/a
    Project MESSAGE: pwd is D:/zw/qmaketest/a
    Project MESSAGE: pwd in common is D:/zw/qmaketest/a
    Project MESSAGE: pwd is D:/zw/qmaketest/a
    Project MESSAGE: pwd in common is D:/zw/qmaketest/a
    Reading D:/zw/qmaketest/common/common.pro
    Project MESSAGE: pwd in common is D:/zw/qmaketest/common
    Project MESSAGE: pwd in common is D:/zw/qmaketest/common
    Project MESSAGE: pwd in common is D:/zw/qmaketest/common
    

    That shou give you a hint
    (edit: added some code-tags)



  • Hi,

    you can try to:

    • rename common.pro to common.pri,
    • include it in your a.pro like this:
    !include(common.pri) {
        error("Ooops..! common.pri is missing")
    }
    
    • inside common.priuse _PRO_FILE_PWD_ variable

    In this case, when you include common.pri inside your a.pro, _PRO_FILE_PWD_ variable will point to the a.pro directory.
    If you later include common.pri inside b.pro, _PRO_FILE_PWD_ will point to the b.pro directory.
    And so on...

    You can read more on the qmake variables page.

    Hope this helps :)



  • it worked using PRO_FILE_PWD variable! Thanks a lot!


Log in to reply
 

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