QMAKE_EXTRA_COMPILERS and MOC
-
I have a problem using QMAKE_EXTRA_COMPILERS to generate source files for QObject derived classes.
It seems like MOC compiler doesn't sees these generated files and project linking fails because of absent MOC generated functions for my classes.
I have to re-run qmake to enforce MOC to generate *_moc.cpp files for my generated classes.Here is a little example of my source files generator.
my_src_gen.name = My Source generator ${QMAKE_FILE_IN} my_src_gen.input = MY_SOURCES my_src_gen.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.my.cpp my_src_gen.commands = $$PWD/my_gen.bat ${QMAKE_FILE_IN} ${QMAKE_FILE_PATH} my_src_gen.CONFIG += target_predeps my_src_gen.variable_out = SOURCES silent:my_src_gen.commands = @echo my_src_gen ${QMAKE_FILE_IN} && $$my_src_gen.commands QMAKE_EXTRA_COMPILERS += my_src_gen
There is a test example project QMAKE_EXTRA_COMPILERS_test (windows) where the problem is reproduced.
How to avoid second qmake invocation there?
-
I had the same problem, solved it by making a new compiler that uses the generated header file as input and runs moc on it to generate the missing source file. From my .pro:
dbc2cpp_canbus_h.name = Generating canbus.h from DBC file.
dbc2cpp_canbus_h.CONFIG += combine
dbc2cpp_canbus_h.input = "DBC_A_C"
dbc2cpp_canbus_h.output = canbus.h
dbc2cpp_canbus_h.commands = bash -c 'dbc2cpp --target CANBUS_H CLUSTER <($${DBC_A_GIT}) <($${DBC_C_GIT})'
dbc2cpp_canbus_h.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += dbc2cpp_canbus_hCANBUS_H = canbus.h
new_moc.commands = moc $(DEFINES) $(INCPATH) canbus.h -o ${QMAKE_FILE_OUT}
new_moc.input = "CANBUS_H"
new_moc.output = moc_canbus.cpp
new_moc.variable_out = SOURCES
QMAKE_EXTRA_COMPILERS += new_moc