Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Nested subdir dependencies on top-level libs

Nested subdir dependencies on top-level libs

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • btseB Offline
    btseB Offline
    btse
    wrote on last edited by
    #1

    I have a project organized like so:

    src/
      cmdline/
        cmdline_app1/
        cmdline_app2/
      app1/
      lib1/
      lib2/
    

    I have a subdirs template defined at the src/ level, which defines the cmdlnie, app1, lib1, lib2. cmdline is another subdirs template, which defines cmdline_app1 and cmdline_app2.

    The problem I've run into is defining dependencies on top-level projects from within the nested subdir projects. For example, how do I define a dependency on lib1 from cmdline_app1? subdir projects are unaware of projects higher up in the hierarchy, aka cmdline subdir is unaware of lib1 project, so I can't just define cmdline_app1.depends = lib2 in the cmdline.pro file.

    I 1 Reply Last reply
    0
    • btseB btse

      I have a project organized like so:

      src/
        cmdline/
          cmdline_app1/
          cmdline_app2/
        app1/
        lib1/
        lib2/
      

      I have a subdirs template defined at the src/ level, which defines the cmdlnie, app1, lib1, lib2. cmdline is another subdirs template, which defines cmdline_app1 and cmdline_app2.

      The problem I've run into is defining dependencies on top-level projects from within the nested subdir projects. For example, how do I define a dependency on lib1 from cmdline_app1? subdir projects are unaware of projects higher up in the hierarchy, aka cmdline subdir is unaware of lib1 project, so I can't just define cmdline_app1.depends = lib2 in the cmdline.pro file.

      I Offline
      I Offline
      Infinity
      wrote on last edited by
      #2

      @btse You need to add this in your .pro files in the subdirs:

      PRE_TARGETDEPS += \
              $$PWD/../../lib1/libyourlib1.a \
              $$PWD/../../lib2/libyourlib2.a \
      
      btseB 1 Reply Last reply
      1
      • I Infinity

        @btse You need to add this in your .pro files in the subdirs:

        PRE_TARGETDEPS += \
                $$PWD/../../lib1/libyourlib1.a \
                $$PWD/../../lib2/libyourlib2.a \
        
        btseB Offline
        btseB Offline
        btse
        wrote on last edited by
        #3

        @Infinity I have this already for all of my projects, in addition to DEPENDPATH. However, this only works when those dependencies have already been built at least once, aka the lib file exists. It won't build the project/lib if it hasn't been built yet.

        I 1 Reply Last reply
        0
        • btseB btse

          @Infinity I have this already for all of my projects, in addition to DEPENDPATH. However, this only works when those dependencies have already been built at least once, aka the lib file exists. It won't build the project/lib if it hasn't been built yet.

          I Offline
          I Offline
          Infinity
          wrote on last edited by Infinity
          #4

          @btse Can you post your src.pro file?

          btseB 1 Reply Last reply
          1
          • I Infinity

            @btse Can you post your src.pro file?

            btseB Offline
            btseB Offline
            btse
            wrote on last edited by
            #5

            @Infinity

            src.pro

            TEMPLATE = subdirs
            SUBDIRS = \
            cmdline \
            app1 \
            lib1 \
            lib2
            
            app1.depends = lib1
            

            cmdline.pro

            TEMPLATE = subdirs
            SUBDIRS = \
            cmdline_app1 \
            cmdline_app2
            
            # Defining dependencies on lib1 or lib2 in this file is not possible
            
            1 Reply Last reply
            0
            • KH-219DesignK Offline
              KH-219DesignK Offline
              KH-219Design
              wrote on last edited by
              #6

              I'm rushing around at work right now, so I do promise to come back and try to help more empathetically later today.

              Meanwhile, as a quick hint, I have gotten my project to do something very close (possibly identical) to what you need, by following this: http://archive.is/https://www.toptal.com/qt/vital-guide-qmake

              My result ended up looking thusly: https://github.com/219-design/qt-qml-project-template-with-ci/blob/d9e4359cf1/main_gui.pro

              I'll come back in a bit when I have time to hopefully pinpoint exactly what is going wrong in your specific case. Meanwhile, HTH!

              www.219design.com
              Software | Electrical | Mechanical | Product Design

              btseB 1 Reply Last reply
              1
              • KH-219DesignK KH-219Design

                I'm rushing around at work right now, so I do promise to come back and try to help more empathetically later today.

                Meanwhile, as a quick hint, I have gotten my project to do something very close (possibly identical) to what you need, by following this: http://archive.is/https://www.toptal.com/qt/vital-guide-qmake

                My result ended up looking thusly: https://github.com/219-design/qt-qml-project-template-with-ci/blob/d9e4359cf1/main_gui.pro

                I'll come back in a bit when I have time to hopefully pinpoint exactly what is going wrong in your specific case. Meanwhile, HTH!

                btseB Offline
                btseB Offline
                btse
                wrote on last edited by
                #7

                @KH-219Design Thanks for those, but I still don't think those capture my scenario. They detail flat structures, where all subdirs at the top level are just projects (apps or libs), and not more subdirs.

                One possible workaround is defining all projects at the top level (src.pro) explicitly, but this has a number of drawbacks, one of which it doesn't play nicely with Qt Creator. (nested subdirs are no longer shown in a tree hierarchy but are all displayed at the top level).

                Example:

                src.pro

                SUBDIRS = cmdline/cmdline_app1
                
                cmdline/cmdline_app1.depends = lib1 lib2
                
                1 Reply Last reply
                0
                • KH-219DesignK Offline
                  KH-219DesignK Offline
                  KH-219Design
                  wrote on last edited by KH-219Design
                  #8

                  Oh. Now I see. "Subdirs within subdirs." Interesting problem. (Sorry I did not read carefully enough originally.) I have a project I can use locally to poke around at this concept. I'll see if I come up with anything tomorrow.

                  www.219design.com
                  Software | Electrical | Mechanical | Product Design

                  KH-219DesignK 1 Reply Last reply
                  2
                  • KH-219DesignK KH-219Design

                    Oh. Now I see. "Subdirs within subdirs." Interesting problem. (Sorry I did not read carefully enough originally.) I have a project I can use locally to poke around at this concept. I'll see if I come up with anything tomorrow.

                    KH-219DesignK Offline
                    KH-219DesignK Offline
                    KH-219Design
                    wrote on last edited by KH-219Design
                    #9

                    I've been doing some experimenting, with no "good news".

                    Meanwhile, in the throes of tweaking all my pro files and getting nowhere, it occurred to me to examine the pro files inside the source code distribution of Qt itself.

                    The results are not encouraging. I found the following files using SUBDIRS and depends, and I peeked into quite a good sampling of them and none of them seem to use depends with something from a "higher" (outer, enclosing) directory. I thought if I could find even just one such example inside Qt itself, then that would unlock the mystery of how to properly do it. (I still think that! If there is such a single working example, then it will prove this is doable.)

                    qtimageformats/src/src.pro:plugins.depends = imageformats
                    qtquickcontrols2/src/src.pro:quickcontrols2.depends = quicktemplates2
                    qtmultimedia/src/src.pro:src_qtmmwidgets.depends = multimedia
                    qtbase/src/src.pro:src_tools_moc.depends = src_tools_bootstrap
                    qtbase/src/platformsupport/platformsupport.pro:    input.depends += devicediscovery
                    qttools/src/designer/src/src.pro:    lib.depends = uiplugin
                    qttools/src/src.pro:            linguist.depends = designer
                    qttools/src/assistant/assistant.pro:assistant.depends = help
                    qtdeclarative/src/plugins/qmltooling/qmltooling.pro:qmldbg_native.depends = packetprotocol
                    

                    ^^ some of the places I turned to, hoping to find inspiration. None found :(

                    All it would take to end the chase is one bit of documentation stating: "targets given as arguments to depends must be targets declared in the same pro file" .... or if that is not true, then an example of how to do it otherwise...

                    Frustrating that I cannot find such explicit documentation. Can anyone?

                    www.219design.com
                    Software | Electrical | Mechanical | Product Design

                    btseB 1 Reply Last reply
                    1
                    • KH-219DesignK KH-219Design

                      I've been doing some experimenting, with no "good news".

                      Meanwhile, in the throes of tweaking all my pro files and getting nowhere, it occurred to me to examine the pro files inside the source code distribution of Qt itself.

                      The results are not encouraging. I found the following files using SUBDIRS and depends, and I peeked into quite a good sampling of them and none of them seem to use depends with something from a "higher" (outer, enclosing) directory. I thought if I could find even just one such example inside Qt itself, then that would unlock the mystery of how to properly do it. (I still think that! If there is such a single working example, then it will prove this is doable.)

                      qtimageformats/src/src.pro:plugins.depends = imageformats
                      qtquickcontrols2/src/src.pro:quickcontrols2.depends = quicktemplates2
                      qtmultimedia/src/src.pro:src_qtmmwidgets.depends = multimedia
                      qtbase/src/src.pro:src_tools_moc.depends = src_tools_bootstrap
                      qtbase/src/platformsupport/platformsupport.pro:    input.depends += devicediscovery
                      qttools/src/designer/src/src.pro:    lib.depends = uiplugin
                      qttools/src/src.pro:            linguist.depends = designer
                      qttools/src/assistant/assistant.pro:assistant.depends = help
                      qtdeclarative/src/plugins/qmltooling/qmltooling.pro:qmldbg_native.depends = packetprotocol
                      

                      ^^ some of the places I turned to, hoping to find inspiration. None found :(

                      All it would take to end the chase is one bit of documentation stating: "targets given as arguments to depends must be targets declared in the same pro file" .... or if that is not true, then an example of how to do it otherwise...

                      Frustrating that I cannot find such explicit documentation. Can anyone?

                      btseB Offline
                      btseB Offline
                      btse
                      wrote on last edited by
                      #10

                      @KH-219Design I think using the

                      .depends 
                      .command
                      .target
                      

                      mechanism is a possibility (https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets). I'll have to do some testing though.

                      I guess the other solution would be to change the structure of my codebase to a more flat structure, but it's quite a large codebase so it'd take a bit of effort, and would kind of defeat the purpose of having subdirs.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved