1 dnl @synopsis BNV_HAVE_QT [--with-Qt-dir=DIR] [--with-Qt-lib-dir=DIR] [--with-Qt-lib=LIB]
2 dnl @synopsis BNV_HAVE_QT [--with-Qt-include-dir=DIR] [--with-Qt-bin-dir=DIR] [--with-Qt-lib-dir=DIR] [--with-Qt-lib=LIB]
4 dnl @summary Search for Trolltech's Qt GUI framework.
6 dnl Searches common directories for Qt include files, libraries and Qt
7 dnl binary utilities. The macro supports several different versions of
8 dnl the Qt framework being installed on the same machine. Without
9 dnl options, the macro is designed to look for the latest library,
10 dnl i.e., the highest definition of QT_VERSION in qglobal.h. By use of
11 dnl one or more options a different library may be selected. There are
12 dnl two different sets of options. Both sets contain the option
13 dnl --with-Qt-lib=LIB which can be used to force the use of a
14 dnl particular version of the library file when more than one are
15 dnl available. LIB must be in the form as it would appear behind the
16 dnl "-l" option to the compiler. Examples for LIB would be "qt-mt" for
17 dnl the multi-threaded version and "qt" for the regular version. In
18 dnl addition to this, the first set consists of an option
19 dnl --with-Qt-dir=DIR which can be used when the installation conforms
20 dnl to Trolltech's standard installation, which means that header files
21 dnl are in DIR/include, binary utilities are in DIR/bin and the library
22 dnl is in DIR/lib. The second set of options can be used to indicate
23 dnl individual locations for the header files, the binary utilities and
24 dnl the library file, in addition to the specific version of the
27 dnl The following shell variable is set to either "yes" or "no":
31 dnl Additionally, the following variables are exported:
39 dnl which respectively contain an "-I" flag pointing to the Qt include
40 dnl directory (and "-DQT_THREAD_SUPPORT" when LIB is "qt-mt"), link
41 dnl flags necessary to link with Qt and X, the name of the meta object
42 dnl compiler and the user interface compiler both with full path, and
43 dnl finaly the variable QTDIR as Trolltech likes to see it defined (if
46 dnl Example lines for Makefile.in:
48 dnl CXXFLAGS = @QT_CXXFLAGS@
51 dnl After the variables have been set, a trial compile and link is
52 dnl performed to check the correct functioning of the meta object
53 dnl compiler. This test may fail when the different detected elements
54 dnl stem from different releases of the Qt framework. In that case, an
55 dnl error message is emitted and configure stops.
57 dnl No common variables such as $LIBS or $CFLAGS are polluted.
61 dnl --with-Qt-dir=DIR: DIR is equal to $QTDIR if you have followed the
62 dnl installation instructions of Trolltech. Header files are in
63 dnl DIR/include, binary utilities are in DIR/bin and the library is in
66 dnl --with-Qt-include-dir=DIR: Qt header files are in DIR.
68 dnl --with-Qt-bin-dir=DIR: Qt utilities such as moc and uic are in DIR.
70 dnl --with-Qt-lib-dir=DIR: The Qt library is in DIR.
72 dnl --with-Qt-lib=LIB: Use -lLIB to link with the Qt library.
74 dnl If some option "=no" or, equivalently, a --without-Qt-* version is
75 dnl given in stead of a --with-Qt-*, "have_qt" is set to "no" and the
76 dnl other variables are set to the empty string.
78 dnl @category InstalledPackages
79 dnl @author Bastiaan Veelo <Bastiaan@Veelo.net>
80 dnl @version 2006-03-12
81 dnl @license AllPermissive
83 dnl Copyright (C) 2001, 2002, 2003, 2005, 2006 Bastiaan Veelo
85 dnl THANKS! This code includes bug fixes and contributions made by:
87 dnl Dennis R. Weilert,
95 dnl 2006-03-12 * Hide output of ls and fix an m4 quoting problem (due to Scott J. Bertin).
96 dnl 2006-02-13 * Check compiler return value instead of parsing the error stream,
97 dnl which detected warnings as false negatives (due to Jens Hannemann).
98 dnl 2006-02-02 * Spelling of "Success".
99 dnl * Fixed unsave test for $bnv_qt_lib without quotes.
100 dnl * Put dnl in front of all comments.
101 dnl * Changed -l$bnv_qt_lib_dir into -L$bnv_qt_lib_dir (all due to Pavel Roskin).
102 dnl 2006-01-19 * Support for 64bit architectures.
103 dnl * Updated documentation.
104 dnl 2006-01-18: * Fix "cat: bnv_qt_test.c: No such file or directory" (due to Jens Hannemann).
105 dnl * Hide output of failing ls.
106 dnl 2006-01-11: * Check in /Developer on Mac OS X; Check in $QTDIR (due to Brian Mingus).
108 dnl Calls BNV_PATH_QT_DIRECT (contained in this file) as a subroutine.
109 AC_DEFUN([BNV_HAVE_QT],
111 AC_REQUIRE([AC_PROG_CXX])
112 AC_REQUIRE([AC_PATH_X])
113 AC_REQUIRE([AC_PATH_XTRA])
115 AC_MSG_CHECKING(for Qt)
117 AC_ARG_WITH([Qt-dir],
118 [ --with-Qt-dir=DIR DIR is equal to $QTDIR if you have followed the
119 installation instructions of Trolltech. Header
120 files are in DIR/include, binary utilities are
121 in DIR/bin. The library is in DIR/lib, unless
122 --with-Qt-lib-dir is also set.])
123 AC_ARG_WITH([Qt-include-dir],
124 [ --with-Qt-include-dir=DIR
125 Qt header files are in DIR])
126 AC_ARG_WITH([Qt-bin-dir],
127 [ --with-Qt-bin-dir=DIR Qt utilities such as moc and uic are in DIR])
128 AC_ARG_WITH([Qt-lib-dir],
129 [ --with-Qt-lib-dir=DIR The Qt library is in DIR])
130 AC_ARG_WITH([Qt-lib],
131 [ --with-Qt-lib=LIB Use -lLIB to link with the Qt library])
132 if test x"$with_Qt_dir" = x"no" ||
133 test x"$with_Qt_include-dir" = x"no" ||
134 test x"$with_Qt_bin_dir" = x"no" ||
135 test x"$with_Qt_lib_dir" = x"no" ||
136 test x"$with_Qt_lib" = x"no"; then
137 # user disabled Qt. Leave cache alone.
138 have_qt="User disabled Qt."
140 # "yes" is a bogus option
141 if test x"$with_Qt_dir" = xyes; then
144 if test x"$with_Qt_include_dir" = xyes; then
147 if test x"$with_Qt_bin_dir" = xyes; then
150 if test x"$with_Qt_lib_dir" = xyes; then
153 if test x"$with_Qt_lib" = xyes; then
156 # No Qt unless we discover otherwise
158 # Check whether we are requested to link with a specific version
159 if test x"$with_Qt_lib" != x; then
160 bnv_qt_lib="$with_Qt_lib"
162 # Check whether we were supplied with an answer already
163 if test x"$with_Qt_dir" != x; then
165 bnv_qt_dir="$with_Qt_dir"
166 bnv_qt_include_dir="$with_Qt_dir/include"
167 bnv_qt_bin_dir="$with_Qt_dir/bin"
168 bnv_qt_lib_dir="$with_Qt_dir/lib"
169 # Only search for the lib if the user did not define one already
170 if test x"$bnv_qt_lib" = x; then
171 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
172 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
174 bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
176 # Use cached value or do search, starting with suggestions from
178 AC_CACHE_VAL(bnv_cv_have_qt,
180 # We are not given a solution and there is no cached value.
182 bnv_qt_include_dir=NO
184 if test x"$bnv_qt_lib" = x; then
188 if test "$bnv_qt_dir" = NO ||
189 test "$bnv_qt_include_dir" = NO ||
190 test "$bnv_qt_lib_dir" = NO ||
191 test "$bnv_qt_lib" = NO; then
192 # Problem with finding complete Qt. Cache the known absence of Qt.
193 bnv_cv_have_qt="have_qt=no"
195 # Record where we found Qt for the cache.
196 bnv_cv_have_qt="have_qt=yes \
197 bnv_qt_dir=$bnv_qt_dir \
198 bnv_qt_include_dir=$bnv_qt_include_dir \
199 bnv_qt_bin_dir=$bnv_qt_bin_dir \
200 bnv_qt_LIBS=\"$bnv_qt_LIBS\""
203 eval "$bnv_cv_have_qt"
204 fi # all $bnv_qt_* are set
205 fi # $have_qt reflects the system status
206 if test x"$have_qt" = xyes; then
207 QT_CXXFLAGS="-I$bnv_qt_include_dir"
208 if test x"$bnv_qt_lib" = xqt-mt; then
209 QT_CXXFLAGS="$QT_CXXFLAGS -DQT_THREAD_SUPPORT"
212 QT_LIBS="$bnv_qt_LIBS"
213 # If bnv_qt_dir is defined, utilities are expected to be in the
215 if test x"$bnv_qt_dir" != x; then
216 if test -x "$bnv_qt_dir/bin/uic"; then
217 QT_UIC="$bnv_qt_dir/bin/uic"
219 # Old versions of Qt don't have uic
222 QT_MOC="$bnv_qt_dir/bin/moc"
224 # Or maybe we are told where to look for the utilities
225 if test x"$bnv_qt_bin_dir" != x; then
226 if test -x "$bnv_qt_bin_dir/uic"; then
227 QT_UIC="$bnv_qt_bin_dir/uic"
229 # Old versions of Qt don't have uic
232 QT_MOC="$bnv_qt_bin_dir/moc"
234 # Last possibility is that they are in $PATH
239 # All variables are defined, report the result
240 AC_MSG_RESULT([$have_qt:
241 QT_CXXFLAGS=$QT_CXXFLAGS
253 AC_MSG_RESULT($have_qt)
255 AC_SUBST(QT_CXXFLAGS)
262 if test x"$have_qt" = xyes; then
263 AC_MSG_CHECKING(correct functioning of Qt installation)
264 AC_CACHE_VAL(bnv_cv_qt_test_result,
266 cat > bnv_qt_test.h << EOF
268 class Test : public QObject
281 cat > bnv_qt_main.$ac_ext << EOF
282 #include "bnv_qt_test.h"
283 #include <qapplication.h>
284 int main( int argc, char **argv )
286 QApplication app( argc, argv );
288 QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) );
292 bnv_cv_qt_test_result="failure"
293 bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>/dev/null"
294 AC_TRY_EVAL(bnv_try_1)
295 if test x"$ac_status" != x0; then
296 echo "$bnv_err_1" >&AC_FD_CC
297 echo "configure: could not run $QT_MOC on:" >&AC_FD_CC
298 cat bnv_qt_test.h >&AC_FD_CC
300 bnv_try_2="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o moc_bnv_qt_test.o moc_bnv_qt_test.$ac_ext >/dev/null 2>/dev/null"
301 AC_TRY_EVAL(bnv_try_2)
302 if test x"$ac_status" != x0; then
303 echo "$bnv_err_2" >&AC_FD_CC
304 echo "configure: could not compile:" >&AC_FD_CC
305 cat moc_bnv_qt_test.$ac_ext >&AC_FD_CC
307 bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>/dev/null"
308 AC_TRY_EVAL(bnv_try_3)
309 if test x"$ac_status" != x0; then
310 echo "$bnv_err_3" >&AC_FD_CC
311 echo "configure: could not compile:" >&AC_FD_CC
312 cat bnv_qt_main.$ac_ext >&AC_FD_CC
314 bnv_try_4="$CXX $QT_LIBS $LIBS -o bnv_qt_main bnv_qt_main.o moc_bnv_qt_test.o >/dev/null 2>/dev/null"
315 AC_TRY_EVAL(bnv_try_4)
316 if test x"$ac_status" != x0; then
317 echo "$bnv_err_4" >&AC_FD_CC
319 bnv_cv_qt_test_result="success"
324 ])dnl AC_CACHE_VAL bnv_cv_qt_test_result
325 AC_MSG_RESULT([$bnv_cv_qt_test_result]);
326 if test x"$bnv_cv_qt_test_result" = "xfailure"; then
327 AC_MSG_ERROR([Failed to find matching components of a complete
328 Qt installation. Try using more options,
329 see ./configure --help.])
332 rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \
333 bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main
337 dnl Internal subroutine of BNV_HAVE_QT
338 dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib
339 AC_DEFUN([BNV_PATH_QT_DIRECT],
341 ## Binary utilities ##
342 if test x"$with_Qt_bin_dir" != x; then
343 bnv_qt_bin_dir=$with_Qt_bin_dir
345 ## Look for header files ##
346 if test x"$with_Qt_include_dir" != x; then
347 bnv_qt_include_dir="$with_Qt_include_dir"
349 # The following header file is expected to define QT_VERSION.
350 qt_direct_test_header=qglobal.h
351 # Look for the header file in a standard set of common directories.
352 bnv_include_path_list="
354 `ls -dr ${QTDIR}/include 2>/dev/null`
355 `ls -dr /usr/include/qt* 2>/dev/null`
356 `ls -dr /usr/lib/qt*/include 2>/dev/null`
357 `ls -dr /usr/local/qt*/include 2>/dev/null`
358 `ls -dr /opt/qt*/include 2>/dev/null`
359 `ls -dr /Developer/qt*/include 2>/dev/null`
361 for bnv_dir in $bnv_include_path_list; do
362 if test -r "$bnv_dir/$qt_direct_test_header"; then
363 bnv_dirs="$bnv_dirs $bnv_dir"
366 # Now look for the newest in this list
368 for bnv_dir in $bnv_dirs; do
369 bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//`
370 if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then
371 bnv_qt_include_dir=$bnv_dir
372 bnv_prev_ver=$bnv_this_ver
375 fi dnl Found header files.
377 # Are these headers located in a traditional Trolltech installation?
378 # That would be $bnv_qt_include_dir stripped from its last element:
379 bnv_possible_qt_dir=`dirname $bnv_qt_include_dir`
380 if (test -x $bnv_possible_qt_dir/bin/moc) &&
381 ((ls $bnv_possible_qt_dir/lib/libqt* > /dev/null 2>/dev/null) ||
382 (ls $bnv_possible_qt_dir/lib64/libqt* > /dev/null 2>/dev/null)); then
383 # Then the rest is a piece of cake
384 bnv_qt_dir=$bnv_possible_qt_dir
385 bnv_qt_bin_dir="$bnv_qt_dir/bin"
386 if test x"$with_Qt_lib_dir" != x; then
387 bnv_qt_lib_dir="$with_Qt_lib_dir"
389 if (test -d $bnv_qt_dir/lib64); then
390 bnv_qt_lib_dir="$bnv_qt_dir/lib64"
392 bnv_qt_lib_dir="$bnv_qt_dir/lib"
395 # Only look for lib if the user did not supply it already
396 if test x"$bnv_qt_lib" = xNO; then
397 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
398 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
400 bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
402 # There is no valid definition for $QTDIR as Trolltech likes to see it
404 ## Look for Qt library ##
405 if test x"$with_Qt_lib_dir" != x; then
406 bnv_qt_lib_dir="$with_Qt_lib_dir"
407 # Only look for lib if the user did not supply it already
408 if test x"$bnv_qt_lib" = xNO; then
409 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
410 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
412 bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
414 # Normally, when there is no traditional Trolltech installation,
415 # the library is installed in a place where the linker finds it
417 # If the user did not define the library name, try with qt
418 if test x"$bnv_qt_lib" = xNO; then
421 qt_direct_test_header=qapplication.h
422 qt_direct_test_main="
425 QApplication app(argc,argv);
427 # See if we find the library without any special options.
428 # Don't add top $LIBS permanently yet
429 bnv_save_LIBS="$LIBS"
430 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
432 bnv_save_CXXFLAGS="$CXXFLAGS"
433 CXXFLAGS="-I$bnv_qt_include_dir"
434 AC_TRY_LINK([#include <$qt_direct_test_header>],
435 $qt_direct_test_main,
438 # We can link with no special library directory.
441 # That did not work. Try the multi-threaded version
442 echo "Non-critical error, please neglect the above." >&AC_FD_CC
444 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
445 AC_TRY_LINK([#include <$qt_direct_test_header>],
446 $qt_direct_test_main,
449 # We can link with no special library directory.
452 # That did not work. Try the OpenGL version
453 echo "Non-critical error, please neglect the above." >&AC_FD_CC
455 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
456 AC_TRY_LINK([#include <$qt_direct_test_header>],
457 $qt_direct_test_main,
460 # We can link with no special library directory.
463 # That did not work. Maybe a library version I don't know about?
464 echo "Non-critical error, please neglect the above." >&AC_FD_CC
465 # Look for some Qt lib in a standard set of common directories.
467 `echo $bnv_qt_includes | sed ss/includess`
475 `ls -dr /usr/lib64/qt* 2>/dev/null`
476 `ls -dr /usr/lib64/qt*/lib64 2>/dev/null`
477 `ls -dr /usr/lib/qt* 2>/dev/null`
478 `ls -dr /usr/local/qt* 2>/dev/null`
479 `ls -dr /opt/qt* 2>/dev/null`
481 for bnv_dir in $bnv_dir_list; do
482 if ls $bnv_dir/libqt* >/dev/null 2>/dev/null; then
483 # Gamble that it's the first one...
484 bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p |
485 sed s@$bnv_dir/lib@@ | sed s/[[.]].*//`"
486 bnv_qt_lib_dir="$bnv_dir"
491 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
492 AC_TRY_LINK([#include <$qt_direct_test_header>],
493 $qt_direct_test_main,
496 # We can link with no special library directory.
499 # Leave bnv_qt_lib_dir defined
504 if test x"$bnv_qt_lib_dir" != x; then
505 bnv_qt_LIBS="-L$bnv_qt_lib_dir $LIBS"
509 LIBS="$bnv_save_LIBS"
510 CXXFLAGS="$bnv_save_CXXFLAGS"
511 fi dnl $with_Qt_lib_dir was not given
512 fi dnl Done setting up for non-traditional Trolltech installation