configuring optional dependencies in qmake or cmake
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.
Re: configuring optional dependencies in qmake or cmake
Do you want to detect the dependency automatically?
On which systems?
Or do you want to have a parameter like "configure --with-my-dependency"?
Re: configuring optional dependencies in qmake or cmake
Quote:
Originally Posted by
tbscope
Do you want to detect the dependency automatically?
If possible, I'd like it to be detected automatically.
I work on Linux but if it is portable, that would be good too.
Quote:
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!
Re: configuring optional dependencies in qmake or cmake
For a simple on/off switch you can just use qmake and a scope:
Code:
has_foo {
message("Has foo")
DEFINES += ENABLE_FOO
INCLUDEPATH += ...
LIBS += ...
}
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += main.cpp
and then either
Code:
$ 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.
Code:
$ 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:
Code:
system(pkg-config --exists foo) {
message("Has foo")
...
}
Re: configuring optional dependencies in qmake or cmake
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?
Re: configuring optional dependencies in qmake or cmake
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.
Re: configuring optional dependencies in qmake or cmake
OK, thanks for the help & info.