PDA

View Full Version : How to know if the build is with Qt



kemp
27th March 2007, 12:36
Hi!

I need to define different variables if the project is built with Qt.
How could i define for example:

#ifdef QtBuild

......
.....

#else

.........

#endif

Thanks for the help.

jpn
27th March 2007, 19:21
How about passing your own compiler define (http://doc.trolltech.com/4.2/qmake-variable-reference.html#defines)?

I'm not exactly sure if there's any common compiler preprocessor macro defined in each and every Qt project. Most of the useful defines are defined in <QtGlobal> which you presumably don't want to include to a non-Qt project.

wysota
27th March 2007, 19:29
How about using "#ifdef QT_VERSION" ?

sdfisher
27th March 2007, 20:13
QT_VERSION is defined by QtGlobal, so I don't think you can do anything based on that. However, I believe you'll find that Qt defines preprocessor symbols for the various libraries you use, so for example you could use QT_CORE_LIB.

#ifdef QT_CORE_LIB
#include <QtGlobal>
#endif
// now QT_VERSION is defined

wysota
27th March 2007, 23:55
QT_VERSION is defined by QtGlobal, so I don't think you can do anything based on that.

I don't really see a problem... If the macro is NOT defined, you know you're NOT using Qt files when compiling this module. Of course if you want to do somehing in a file which doesn't include anything "Qt-ish" but is consolidated with Qt code later on then relying on QtGlobal is not possible. But relying on other Qt-defined macros is possible only when qmake is informed it is to use Qt with the project. So you can't rely on it when compiling (for example) some libraries or modules which will then be used by a Qt-based project. The best choice really is to do what J-P suggested - use a custom macro of your own.

sdfisher
28th March 2007, 01:02
The question was "I need to define different variables if the project is built with Qt."

Part of the problem is defining what "built with Qt" means. I took it at face value, which is to say built with qmake. Do Makefiles generated with qmake define QT_CORE_LIB? If so, you can detect Qt's building system that way. If not, I agree it's useless.

kemp
28th March 2007, 07:01
Hi to all!

Yes I mean a project generated with qmake.
Thanks for the help.

wysota
28th March 2007, 07:57
Do Makefiles generated with qmake define QT_CORE_LIB? If so, you can detect Qt's building system that way.

They do, unless you tell qmake not to use Qt (CONFIG-=qt afair).