I realized my earlier question was a little confused about the rules and dependencies. The following .pro file generates a makefile which works correctly IF the source files in the directory 'generated' exist at the time qmake runs.
idl.target = generated/qmtest.h
idl.commands = code_generator
idl.config = no_link
idl.depends = $$SOURCES $$HEADERS $$FORMS
TEMPLATE = app
INCLUDEPATH += generated
SOURCES += generated/*.cpp
PRE_TARGETDEPS += generated/qmtest.h
QMAKE_EXTRA_UNIX_TARGETS += idl
But when qmake runs, its only generating a makefile, and PRE_TARGETDEPS & QMAKE_EXTRA_UNIX_TARGETS don't help me. How can I get qmake to generate a makefile which will add the contents of generated/ to SOURCES?
Best Answer
You may need to do this in two passes.
In your qmake file, add the following line:
Then, at the end of your code_generator script, add the sources to the generated.pri file (using bash for the example, but the idea is the same for almost all languages):
The first time you run the qmake file, generated/generated.pri will presumably be empty. When you run make, it will populate the generated.pri file. The second time, it will recreate the make file (as a source .pri file changed), then compile again. You might be able to fiddle around with other commands which would do the second stage for you.