0

I have a Qt project that contains many sub-projects. I'm having an issue where one of the projects generates files (.cpp and .h files) that are used in a few of the other projects. Here's an example of the directory structure:

src
 \- master.pro
 \- project1
     \- project1.pro
      - myHeader.h <generated AFTER project1.pro runs>
      - mySource.cpp <generated AFTER project1.pro runs>
 \- project2
     \- project2.pro <needs to include mySource.cpp>
      - main.cpp <includes myHeader.h>
 \- project3
     \- project3.pro <needs to include mySource.cpp>
      - main.cpp <includes myHeader.h>

To be a little more specific, project2 and project3 above are actually server and client projects respectively and they use RPC calls to communicate between the two programs. To generate the RPC files needed by both project2/3 above I created project1 to run the midl.exe compiler commands.

If I compile project1 first manually, then compile project2 and project3 manually then everything works fine. However, if I put the three projects into a Qt subdirs project and have project2/3 dependent on project1 it doesn't work. The issue being that when qmake is run on project2/3 the generated files don't exist yet, but these files DO exist after project1 actually compiles.

So is there a way to somehow put all three of these projects into one subdirs project and somehow 'defer' the qmake on the dependent projects? or maybe make it so the dependent projects know that those files may not exist at the time of qmake, but will exist at the time of compiling?

Thanks in advance for any advice.

Edit

Just a little more info. Here is what my master.pro file looks like

TEMPLATE = subdirs

SUBDIRS += project1 project2 project3

project1.file = $$PWD/project1/project1.pro
project2.file = $$PWD/project2/project2.pro
project2.depends = project1
project3.file = $$PWD/project3/project3.pro
project3.depends = project1
drescherjm
  • 10,365
  • 5
  • 44
  • 64
Stanton
  • 904
  • 10
  • 25
  • Get/use a better build system that is able to correctly track dependencies. Or, configure the one you use correctly (if it *is* actually capable of tracking dependencies correctly, but not doing so currently). – Jesper Juhl Feb 25 '19 at 20:53
  • So you actually want qmake to assume certain files you list exist when creating Makefiles, when they don't actually exist yet? Btw, check out https://stackoverflow.com/questions/11079398/how-to-set-build-order-in-qt-subdir-project too – hyde Feb 25 '19 at 20:58
  • @hyde yes that's right. Since some of the files that are used in the dependent projects (e.g. `project2/3`) are actually generated by another project (e.g. `project1`) – Stanton Feb 26 '19 at 11:22
  • The usual way to handle this would be, that dependency project create library files, which are then used in dependent projects. IOW, is it option for you to actually also compile the generated .cpp files into a library? – hyde Feb 26 '19 at 11:39
  • And if you add `CONFIG+=ordered`, will it work then? You may also try to remove all `xxx.file=yyy` lines, as they seem meaningless. – Matt Feb 26 '19 at 12:04
  • @Matt some of my projects are nested a few folders deeper so I need the path to the file (my example above only shows each project as being one folder deep). Also, I've tried the `CONFIG+=ordered` flag and it doesn't work since again qmake ends up running (and throwing 'missing file' errors) before `project1` can generate the necessary files. – Stanton Feb 26 '19 at 13:43
  • `ordered` forces left-to-right processing (unless `make -jn` used, and this is why it's not recommended anymore), so if it doesn't work for you then you have some more sophisticated inter-project dependencies than you've showed to us. You should check'em carefully. – Matt Feb 26 '19 at 14:49

0 Answers0