Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Nested subdir dependencies on top-level libs
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.
Infinity last edited by
@btse You need to add this in your .pro files in the subdirs:
PRE_TARGETDEPS += \ $$PWD/../../lib1/libyourlib1.a \ $$PWD/../../lib2/libyourlib2.a \
@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.
Infinity last edited by Infinity
TEMPLATE = subdirs SUBDIRS = \ cmdline \ app1 \ lib1 \ lib2 app1.depends = lib1
TEMPLATE = subdirs SUBDIRS = \ cmdline_app1 \ cmdline_app2 # Defining dependencies on lib1 or lib2 in this file is not possible
KH-219Design last edited by
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!
@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).
SUBDIRS = cmdline/cmdline_app1 cmdline/cmdline_app1.depends = lib1 lib2
KH-219Design last edited by 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-219Design last edited by 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
dependswith 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
dependsmust be targets declared in the same
profile" .... 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?
@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.