0

I'd like to be able to pass arguments to the moc compiler from a qmake project, but only for specific files.

Example, in some .pro file:

HEADER += foo.h \
          bar.h \
          baz.h

I'd like to pass -ffoo_extra.h to foo.h, -fbar_extra.h to bar.h, and nothing to baz.h

This answer suggests using the QMAKE_MOC variable, but that affects all headers together. Something like that but targeted to individual header files would be ideal.

Community
  • 1
  • 1
Scott
  • 23
  • 5

1 Answers1

0

The -f argument adds an include to the generated output. You can achieve the same by leveraging the Q_MOC_RUN macro. It's even documented - together with command line options, no less :)

// foo.h
#ifdef Q_MOC_RUN
#include "foo_extra.h"
#endif
...

// bar.h
#ifdef Q_MOC_RUN
#include "bar_extra.h"
#endif
...
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • It looks like this is the only practical way. – Scott May 06 '16 at 14:55
  • Was hoping for something less invasive (reworking a external project to work with qmake instead of cmake in this case, didn't really want to edit the files), and more general (e.g. passing options to individual files in other areas, not just moc) Will mark it as answered – Scott May 06 '16 at 15:01