Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qmake: how to handle dependencies to parallel but otherwise independent projects?



  • Info: Qt 5.3.2 with MinGW on Windows

    I've got the following situation:

    I have a stand alone project building a library. In two parallel source trees I've got other projects (very complex and independent from each other) building applications. Both applications depend on the library at some point (usually somewhere deep down in their respective tree). While the code for all projects is always in the same place relative to each other I cannot create a subdirs-project on the source-"root":

    [root]
       |- [mylibrary]
       |      |-mylibrary.pro        // lib project
       |      ...
       | - [application1]
       |      |- application1.pro    // subdirs project
       |      |- [module11]
       |      |- [module12]          // dll, depends on mylibrary 
       |     ...
       | - [application2]
       |      |- application2.pro    // subdirs project
       |      |- [module21]          // dll, depends on mylibrary 
       |      |- [subdir22]
       |      |      |- [submodule221]    // dll, depends on mylibrary 
       |     ...
      ...
    

    Depending on certain factors usually only one of the applications (or sometimes just one of their modules) is built. Is there any way to create a dependency so mylibrary is built, too, if the application otr module depends on it?

    I tried using subdirs-projects that included mylibrary directly or in subdirectories:

    TEMPLATE = subdirs
    SUBDIRS += module_11 module_12 my_library
    
    my_library.subdir = $$PWD/../mylibrary
    my_library.target = mylibrary
    
    module_11.subdir = $$PWD/module11
    module_11.target = module11
    
    module_12.subdir = $$PWD/module12
    module_12.target = module12
    module_12.depends = mylibrary
    

    Unfortunately this results in qnake creating Makefiles, then calling mingw32-make that is then switching to mylibrary-dir and falling into a loop there, creating more and more instances of mingw32-make switching to mylibrary-dir and falling into a loop there, creating more and more instances of mingw32-make switching to ... you get it.

    Is there any way to get such out-of-source-tree-dependencies builtwithout having to create a subdirs project above them?


  • Moderators

    Hi, welcome to devnet.

    I haven't tried that but something along these lines might work:

    TEMPLATE = subdirs
    SUBDIRS += module_11 module_12 my_library
    
    module_11.subdir = $PWD/module11
    module_11.target = module11
    
    module_12.subdir = $PWD/module12
    module_12.target = module12
    
    my_library.target = mylibrary.a
    my_library.command = make <wherever the library makefile is>
    
    QMAKE_EXTRA_TARGETS += my_library
    PRE_TARGETDEPS += mylibrary.a
    


  • Hi Chris,

    thank you for your answer. Unfortuantely your suggestion doesn't work. I think it's because subdirs projects don't create targets and thus ignore QMAKE_EXTRA_TARGETS and PRE_TARGETDEPS (though <customtarget>.depends does basically the same as PRE_TARGETDEPS).
    Also <target>.command does not seem to be supported in subdirs projects.

    But your suggestion gave me the idea that I maybe could abuse one of the other TEMPLATE types to create custom targets that copy somestuff and replace some paths using your approach with QMAKE_EXTRA_TARGETS etc.


Log in to reply