tags:

views:

227

answers:

1

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?

+1  A: 

You may need to do this in two passes.

In your qmake file, add the following line:

include( generated/generated.pri )

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):

rm generated/generated.pri
for file in $( ls generated/*.cpp ); do
    echo "SOURCES += ${file}" >> generated/generated.pri
done

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.

Caleb Huitt - cjhuitt
Thanks - I ended up forcing the generator to run during qmake using system($$idl.commands). The makefile it generates is correct and since I added the output to the target it doesn't really hurt anything.
swarfrat