[Interest] generated header file not being processed by moc (SOLVED, or rather, maimed)

Glen Mabey gmabey at swri.org
Tue Feb 14 22:59:00 CET 2017


Well, I have the strangest of solutions that isn’t clean, pretty, or even explainable (by me).

Consider these extra rules (linux only) so the complete .pro file looks like this:


TEMPLATE = app

SOURCES += main.cpp

OBJ_SOURCE = dummy_input_file.txt

OBJ_GENERATOR.CONFIG   += no_link target_predeps
OBJ_GENERATOR.output   = ${QMAKE_FILE_BASE}_QObject.h
OBJ_GENERATOR.commands = ./generate_a_file.py ${QMAKE_FILE_OUT}
OBJ_GENERATOR.input = OBJ_SOURCE
OBJ_GENERATOR.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += OBJ_GENERATOR

PRO_FILE_TOUCHER.CONFIG   += no_link target_predeps
PRO_FILE_TOUCHER.output   = .lmp_${QMAKE_FILE_BASE}_generated
PRO_FILE_TOUCHER.commands = touch $$_PRO_FILE_ ${QMAKE_FILE_OUT} && $(MAKE) && exit 1
PRO_FILE_TOUCHER.input    = OBJ_SOURCE
QMAKE_EXTRA_COMPILERS     += PRO_FILE_TOUCHER

OBJECTS_DIR=.o
MOC_DIR=.moc


That is, the first time that make runs, it touches the .pro file as well as .lmp_dummy_input_file_generated, then re-runs make.

Here’s what I don’t understand: when those commands are followed by “exit 1” then for some reason the “new” version of the Makefile gets used in the rest of the build commands, whereas if “exit 0” is used, then in the Makefile, OBJECTS does not contain .o/moc_dummy_input_file_QObject.o and linking fails …

So, this all seems extremely hackish, and make still returns with a non-zero value (like it does when linking fails) but now in this case it actually has succeeded … blech.

Glen

> On Feb 13, 2017, at 12:04 PM, Glen Mabey <gmabey at swri.org> wrote:
> 
> Hello,
> 
> I think I’ve got the exact problem described here back in 2012: https://forum.qt.io/topic/21964/qmake-custom-compilers-how-to-process-generated-header-files-with-moc
> 
> That is, my generated header file includes a class that inherits from QObject and needs to be moc'ed.
> 
> However, these lines are not sufficient to make that happen the first time the project is built:
> 
> OBJ_SOURCE = dummy_input_file.txt
> 
> OBJ_GENERATOR.CONFIG   += no_link target_predeps
> OBJ_GENERATOR.output   = ${QMAKE_FILE_BASE}_QObject.h
> OBJ_GENERATOR.commands = ./generate_a_file.py ${QMAKE_FILE_OUT}
> OBJ_GENERATOR.input = OBJ_SOURCE
> OBJ_GENERATOR.variable_out = HEADERS
> QMAKE_EXTRA_COMPILERS += OBJ_GENERATOR
> 
> 
> That is, the project fails to link due to undefined references.
> 
> If I rerun qmake and build again, though, everything works out fine.
> 
> Any suggestions?
> Glen
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list