Search code examples
qtqmakemoc

How to add specific flags to moc in a qmake project?


I compile a Qt executable using qmake && make on the following project.pro file:

INCLUDEPATH *= ../../dependencies/boost
QT *= opengl xml
CONFIG *= qt opengl static

TARGET = myexe
HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp
SOURCES = main.cpp Viewer.cpp MainWindow.cpp Inspector.cpp

However, when compiling, moc chokes on a boost macro which it cannot parse. To work around this bug, I need to pass the flag -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED to moc, but I cannot manage to do so.

How to I edit my .pro file to pass a given flag to moc? (but not to g++, as QMAKE_CXXFLAGS does)


Solution

  • A bit hackish, but what about if you overwrite the moc compiler so that it includes the flag. In the .pro:

    QMAKE_MOC = $$QMAKE_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED