Question

I'm creating another build automation tool but I'd need to get the finale variable contents , as they are in the makefile produced by qmake, but without generating all the makefile... Is there a way (by creating another template for example, or querying qmake...) to get all the includes, the links etc... ?

(no matter the output format, I just want the path in a fast way)

PS : I've already tried to use message() on the qmake variable, but it outs empty strings

Was it helpful?

Solution

Have you seen the output of the command-line qmake -query ...?

On my system it gives (removed much of the output for clarity):

~ sez$ env PATH=$HOME/build/qt5/qtbase/bin qmake -query
QT_SYSROOT:
QT_INSTALL_PREFIX:/usr/local/Qt-5.2.0
QT_INSTALL_DATA:/usr/local/Qt-5.2.0
QT_INSTALL_HEADERS:/usr/local/Qt-5.2.0/include
QT_INSTALL_LIBS:/usr/local/Qt-5.2.0/lib
QMAKE_SPEC:macx-clang
QMAKE_VERSION:3.0
QT_VERSION:5.2.0

Its less verbose in earlier versions. You can query individual variables like this:

~ sez$ env PATH=$HOME/build/qt5/qtbase/bin qmake -query QT_INSTALL_HEADERS
/usr/local/Qt-5.2.0/include

does that do what you need? Beware of the fact that it will report the location the files are installed to by the make install at the time Qt was built. That means that if you have built Qt but not run "make install" the results of qmake -query won't give you a useful answer.

If you have built from sources and want to use then out of that build directory, then you'd need to run ./configure -prefix=$PWD, and then make install.

EDIT:

For one of my qmake generated Makefiles I have -

INCPATH = -I/usr/local/Qt-5.2.0/mkspecs/macx-clang -I/Users/sez/depot/plistinator/src -I/usr/local/Qt-5.2.0/lib/QtWidgets.framework/Versions/5/Headers -I/usr/local/Qt-5.2.0/lib/QtXml.framework/Versions/5/Headers -I/usr/local/Qt-5.2.0/lib/QtGui.framework/Versions/5/Headers -I/usr/local/Qt-5.2.0/lib/QtCore.framework/Versions/5/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/usr/local/Qt-5.2.0/lib

This is dependent on which Qt modules have been specified for example

QT += widgets xml

Given that information you could reconstruct the above INCPATH using whatever environment you're automating in, eg for bash shell expressions part of one might be

XML_INC=$(qmake -query QT_INSTALL_LIBS)/QtXml.framework/Versions/5/Headers

To get the mkspecs include you could do

MKSPEC_INC=$(qmake -query QT_INSTALL_PREFIX)/mkspecs/$(qmake -query QMAKE_SPEC)

With respect to the GL paths in the SDK those will always be included for Qt, so you could construct them by capturing the output from gcc -v.

Then combine all these *_INC vars into the final result.

Coming up with a complete script for this is beyond the scope of this answer but I think this approach would get you there. I can't think of an easier way to do what you want without actually generating the Makefile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top