PDA

View Full Version : configuring optional dependencies in qmake or cmake



brixton
2nd December 2010, 00:25
Hi,
I have a program that I'm working on which has an optional dependency. In my code I have the appropriate #ifdef ENABLE_DEPENENCY ... #endif block, which works fine.

However, I want to make a source package that I can distribute which will allow the user to do the equivalent of the normal "configure; make; make install" in which the presence or absence of the optional dependency is detected and #define is called (or not!) appropriately.

I'm just not sure how to best do this in qmake. Can anyone point me to some documentation. Is it better to use cmake?

Thanks, B.

tbscope
2nd December 2010, 05:30
Do you want to detect the dependency automatically?
On which systems?

Or do you want to have a parameter like "configure --with-my-dependency"?

brixton
2nd December 2010, 05:56
Do you want to detect the dependency automatically?
If possible, I'd like it to be detected automatically.


On which systems?
I work on Linux but if it is portable, that would be good too.


Or do you want to have a parameter like "configure --with-my-dependency"?I would like to have the dependency inlcuded if it is found but offer a "--without-dependency" option.

Thanks for the help, tbscope!

ChrisW67
2nd December 2010, 06:22
For a simple on/off switch you can just use qmake and a scope:


has_foo {
message("Has foo")
DEFINES += ENABLE_FOO
INCLUDEPATH += ...
LIBS += ...
}


TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp

and then either


$ qmake CONFIG+=has_foo
OR
$ qmake


On Linux platform you can often use pkg-config to test the availability of a given library and obtain the correct include and/or lib paths.


$ pkg-config --exists QtGui && echo "QtGui exists"
QtGui exists
$ pkg-config --cflags QtGui
-DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore
$ pkg-config --libs QtGui
-L/usr/lib/qt4 -lQtGui -lQtCore


You can combine that into the qmake pro file:


system(pkg-config --exists foo) {
message("Has foo")
...
}

brixton
2nd December 2010, 08:45
Thanks Chris, that's all very useful information. I've added a conditional check and it works fine.

Out of curiosity, do most projects which are distributed by source use this method of configuring Makefiles?

ChrisW67
2nd December 2010, 22:04
No, I think that most projects doing mass distribution of source code include an autoconf configure script. Cmake is becoming more common also. I've not had much to do with building Qt apps using either approach.

brixton
3rd December 2010, 20:51
OK, thanks for the help & info.