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

依然范特西╮ 提交于 2019-11-29 10:02:55

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
Programista

In my code in header files I just have:

#ifndef Q_MOC_RUN
    //Here we include Boost or Ogre headers with Macro
#endif

It works perfectly in Qt5 x64 and need not recompiling anything.

There is an update to this issue for boost 1.53, see the last post here:

We need to add -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION also.

For add specific flags to moc in a qmake project(qt5.2) need:

    load(moc)
    QMAKE_MOC += -DBOOST_INCLUDE_GUARD_GOES_HERE

See for example the Qmake docs for variables which details

  • ten different variables in the QMAKE_CFLAGS_* pattern, and

  • ten different variables in the QMAKE_CXXFLAGS* pattern

and hence I would start with QMAKE_CXXFLAGS which is documented as:

QMAKE_CXXFLAGS

This variable contains the C++ compiler flags that are used when building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified. The flags specific to debug and release modes can be adjusted by modifying the QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE variables, respectively. Note: On the Symbian platform, this variable can be used to pass architecture specific options to each compiler in the Symbian build system. For example:

QMAKE_CXXFLAGS.CW += -O2
QMAKE_CXXFLAGS.ARMCC += -O0 

For more information, see qmake Platform Notes.

So I'd start with

QMAKE_CXXFLAGS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

which you can just add to your .pro file.

In case you are doing Ogre3D (OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit) ) then use QT5 32bit instead of the QT5 64bit version, it will pass.

Also consider this :

#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif

I think it has been compiled (boost included) with 32bit thus i suppose i have to take src and recompile (using my 64bit) but thats another story where i wont go for now since OGRE 1.9 RC 1 SDK for Visual C++ .Net 2012 (64-bit) will be soon release on stable version.

Regards

EDIT 1 :

Downloaded Qt libraries 4.8.4 for Windows and configured my QT creator (the one coming with full QT5 and guess what …. Ogre3D is working like a charm when compiling on 4.8.4.

Qt 5.0.2 for Windows 32-bit (VS 2010, 485 MB)
Qt libraries 4.8.4 for Windows (VS 2010, 234 MB)
OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit)

I also mentionned it for who is interested here : http://qt-project.org/forums/viewreply/128660/

The best way I found to do this is based on a comment on the accepted solution from David Faure:

QMAKE_MOC_OPTIONS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

The other proposed methods that involve load(moc) and manipulating the QMAKE_MOC variable itself have an unfortunate side effect: they prevent qmake from automatically adding INCLUDEPATH variables (and maybe others) that would normally be on moc's command line, if INCLUDEPATH is set up after the call to load(moc).

This approach composes easier if you have your qmake configuration split up to multiple files; you don't need to ensure that the change to the moc command line comes after all INCLUDEPATH directories are set.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!