1 dnl Available from the GNU Autoconf Macro Archive at:
2 dnl http://www.gnu.org/software/ac-archive/htmldoc/bnv_have_qt.html
4 AC_DEFUN([BNV_HAVE_QT],
6 dnl THANKS! This code includes bug fixes by:
9 AC_REQUIRE([AC_PROG_CXX])
10 AC_REQUIRE([AC_PATH_X])
11 AC_REQUIRE([AC_PATH_XTRA])
13 AC_MSG_CHECKING(for Qt)
16 [ --with-Qt-dir=DIR DIR is equal to \$QTDIR if you have followed the
17 installation instructions of Trolltech. Header
18 files are in DIR/include, binary utilities are
19 in DIR/bin and the library is in DIR/lib])
20 AC_ARG_WITH([Qt-include-dir],
21 [ --with-Qt-include-dir=DIR
22 Qt header files are in DIR])
23 AC_ARG_WITH([Qt-bin-dir],
24 [ --with-Qt-bin-dir=DIR Qt utilities such as moc and uic are in DIR])
25 AC_ARG_WITH([Qt-lib-dir],
26 [ --with-Qt-lib-dir=DIR The Qt library is in DIR])
28 [ --with-Qt-lib=LIB Use -lLIB to link with the Qt library])
29 if test x"$with_Qt_dir" = x"no" ||
30 test x"$with_Qt_include-dir" = x"no" ||
31 test x"$with_Qt_bin_dir" = x"no" ||
32 test x"$with_Qt_lib_dir" = x"no" ||
33 test x"$with_Qt_lib" = x"no"; then
34 # user disabled Qt. Leave cache alone.
35 have_qt="User disabled Qt."
37 # "yes" is a bogus option
38 if test x"$with_Qt_dir" = xyes; then
41 if test x"$with_Qt_include_dir" = xyes; then
44 if test x"$with_Qt_bin_dir" = xyes; then
47 if test x"$with_Qt_lib_dir" = xyes; then
50 if test x"$with_Qt_lib" = xyes; then
53 # No Qt unless we discover otherwise
55 # Check whether we are requested to link with a specific version
56 if test x"$with_Qt_lib" != x; then
57 bnv_qt_lib="$with_Qt_lib"
59 # Check whether we were supplied with an answer already
60 if test x"$with_Qt_dir" != x; then
62 bnv_qt_dir="$with_Qt_dir"
63 bnv_qt_include_dir="$with_Qt_dir/include"
64 bnv_qt_bin_dir="$with_Qt_dir/bin"
65 bnv_qt_lib_dir="$with_Qt_dir/lib"
66 # Only search for the lib if the user did not define one already
67 if test x"$bnv_qt_lib" = x; then
68 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
69 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
71 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"
73 # Use cached value or do search, starting with suggestions from
75 AC_CACHE_VAL(bnv_cv_have_qt,
77 # We are not given a solution and there is no cached value.
81 if test x"$bnv_qt_lib" = x; then
85 if test "$bnv_qt_dir" = NO ||
86 test "$bnv_qt_include_dir" = NO ||
87 test "$bnv_qt_lib_dir" = NO ||
88 test "$bnv_qt_lib" = NO; then
89 # Problem with finding complete Qt. Cache the known absence of Qt.
90 bnv_cv_have_qt="have_qt=no"
92 # Record where we found Qt for the cache.
93 bnv_cv_have_qt="have_qt=yes \
94 bnv_qt_dir=$bnv_qt_dir \
95 bnv_qt_include_dir=$bnv_qt_include_dir \
96 bnv_qt_bin_dir=$bnv_qt_bin_dir \
97 bnv_qt_LIBS=\"$bnv_qt_LIBS\""
100 eval "$bnv_cv_have_qt"
101 fi # all $bnv_qt_* are set
102 fi # $have_qt reflects the system status
103 if test x"$have_qt" = xyes; then
104 QT_CXXFLAGS="-I$bnv_qt_include_dir"
106 QT_LIBS="$bnv_qt_LIBS"
107 # If bnv_qt_dir is defined, utilities are expected to be in the
109 if test x"$bnv_qt_dir" != x; then
110 if test -x "$bnv_qt_dir/bin/uic"; then
111 QT_UIC="$bnv_qt_dir/bin/uic"
113 # Old versions of Qt don't have uic
116 QT_MOC="$bnv_qt_dir/bin/moc"
118 # Or maybe we are told where to look for the utilities
119 if test x"$bnv_qt_bin_dir" != x; then
120 if test -x "$bnv_qt_bin_dir/uic"; then
121 QT_UIC="$bnv_qt_bin_dir/uic"
123 # Old versions of Qt don't have uic
126 QT_MOC="$bnv_qt_bin_dir/moc"
128 # Last possibility is that they are in $PATH
133 # All variables are defined, report the result
134 AC_MSG_RESULT([$have_qt:
135 QT_CXXFLAGS=$QT_CXXFLAGS
147 AC_MSG_RESULT($have_qt)
149 AC_SUBST(QT_CXXFLAGS)
156 if test x"$have_qt" = xyes; then
157 AC_MSG_CHECKING(correct functioning of Qt installation)
158 AC_CACHE_VAL(bnv_cv_qt_test_result,
160 cat > bnv_qt_test.h << EOF
162 class Test : public QObject
175 cat > bnv_qt_main.$ac_ext << EOF
176 #include "bnv_qt_test.h"
177 #include <qapplication.h>
178 int main( int argc, char **argv )
180 QApplication app( argc, argv );
182 QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) );
186 bnv_cv_qt_test_result="failure"
187 bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>bnv_qt_test_1.out"
188 AC_TRY_EVAL(bnv_try_1)
189 bnv_err_1=`grep -v '^ *+' bnv_qt_test_1.out | grep -v "^bnv_qt_test.h\$"`
190 if test x"$bnv_err_1" != x; then
191 echo "$bnv_err_1" >&AC_FD_CC
192 echo "configure: could not run $QT_MOC on:" >&AC_FD_CC
193 cat bnv_qt_test.h >&AC_FD_CC
195 bnv_try_2="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o moc_bnv_qt_test.o moc_bnv_qt_test.$ac_ext >/dev/null 2>bnv_qt_test_2.out"
196 AC_TRY_EVAL(bnv_try_2)
197 bnv_err_2=`grep -v '^ *+' bnv_qt_test_2.out | grep -v "^bnv_qt_test.{$ac_ext}\$"`
198 if test x"$bnv_err_2" != x; then
199 echo "$bnv_err_2" >&AC_FD_CC
200 echo "configure: could not compile:" >&AC_FD_CC
201 cat bnv_qt_test.$ac_ext >&AC_FD_CC
203 bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>bnv_qt_test_3.out"
204 AC_TRY_EVAL(bnv_try_3)
205 bnv_err_3=`grep -v '^ *+' bnv_qt_test_3.out | grep -v "^bnv_qt_main.{$ac_ext}\$"`
206 if test x"$bnv_err_3" != x; then
207 echo "$bnv_err_3" >&AC_FD_CC
208 echo "configure: could not compile:" >&AC_FD_CC
209 cat bnv_qt_main.$ac_ext >&AC_FD_CC
211 bnv_try_4="$CXX $QT_LIBS $LIBS -o bnv_qt_main bnv_qt_main.o moc_bnv_qt_test.o >/dev/null 2>bnv_qt_test_4.out"
212 AC_TRY_EVAL(bnv_try_4)
213 bnv_err_4=`grep -v '^ *+' bnv_qt_test_4.out`
214 if test x"$bnv_err_4" != x; then
215 echo "$bnv_err_4" >&AC_FD_CC
217 bnv_cv_qt_test_result="success"
222 ])dnl AC_CACHE_VAL bnv_cv_qt_test_result
223 AC_MSG_RESULT([$bnv_cv_qt_test_result]);
224 if test x"$bnv_cv_qt_test_result" = "xfailure"; then
225 # working Qt was not found
232 AC_MSG_WARN([Failed to find matching components of a complete
233 Qt installation. Try using more options,
234 see ./configure --help.])
237 rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \
238 bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main \
239 bnv_qt_test_1.out bnv_qt_test_2.out bnv_qt_test_3.out bnv_qt_test_4.out
243 dnl Internal subroutine of BNV_HAVE_QT
244 dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib
245 dnl Copyright 2001 Bastiaan N. Veelo <Bastiaan.N.Veelo@immtek.ntnu.no>
246 AC_DEFUN([BNV_PATH_QT_DIRECT],
248 ## Binary utilities ##
249 if test x"$with_Qt_bin_dir" != x; then
250 bnv_qt_bin_dir=$with_Qt_bin_dir
252 ## Look for header files ##
253 if test x"$with_Qt_include_dir" != x; then
254 bnv_qt_include_dir="$with_Qt_include_dir"
256 # The following header file is expected to define QT_VERSION.
257 qt_direct_test_header=qglobal.h
258 # Look for the header file in a standard set of common directories.
259 bnv_include_path_list="
261 `ls -dr /usr/include/qt* 2>/dev/null`
262 `ls -dr /usr/lib/qt*/include 2>/dev/null`
263 `ls -dr /usr/local/qt*/include 2>/dev/null`
264 `ls -dr /opt/qt*/include 2>/dev/null`
266 for bnv_dir in $bnv_include_path_list; do
267 if test -r "$bnv_dir/$qt_direct_test_header"; then
268 bnv_dirs="$bnv_dirs $bnv_dir"
271 # Now look for the newest in this list
273 for bnv_dir in $bnv_dirs; do
274 bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//`
275 if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then
276 bnv_qt_include_dir=$bnv_dir
277 bnv_prev_ver=$bnv_this_ver
280 fi dnl Found header files.
282 # Are these headers located in a traditional Trolltech installation?
283 # That would be $bnv_qt_include_dir stripped from its last element:
284 bnv_possible_qt_dir=`dirname $bnv_qt_include_dir`
285 if test -x $bnv_possible_qt_dir/bin/moc &&
286 ls $bnv_possible_qt_dir/lib/libqt* > /dev/null; then
287 # Then the rest is a piece of cake
288 bnv_qt_dir=$bnv_possible_qt_dir
289 bnv_qt_bin_dir="$bnv_qt_dir/bin"
290 bnv_qt_lib_dir="$bnv_qt_dir/lib"
291 # Only look for lib if the user did not supply it already
292 if test x"$bnv_qt_lib" = xNO; then
293 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
294 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
296 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"
298 # There is no valid definition for $QTDIR as Trolltech likes to see it
300 ## Look for Qt library ##
301 if test x"$with_Qt_lib_dir" != x; then
302 bnv_qt_lib_dir="$with_Qt_lib_dir"
303 # Only look for lib if the user did not supply it already
304 if test x"$bnv_qt_lib" = xNO; then
305 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
306 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
308 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"
310 # Normally, when there is no traditional Trolltech installation,
311 # the library is installed in a place where the linker finds it
313 # If the user did not define the library name, try with qt
314 if test x"$bnv_qt_lib" = xNO; then
317 qt_direct_test_header=qapplication.h
318 qt_direct_test_main="
321 QApplication app(argc,argv);
323 # See if we find the library without any special options.
324 # Don't add top $LIBS permanently yet
325 bnv_save_LIBS="$LIBS"
326 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
328 bnv_save_CXXFLAGS="$CXXFLAGS"
329 CXXFLAGS="-I$bnv_qt_include_dir"
330 AC_TRY_LINK([#include <$qt_direct_test_header>],
331 $qt_direct_test_main,
334 # We can link with no special library directory.
337 # That did not work. Try the multi-threaded version
338 echo "Non-critical error, please neglect the above." >&AC_FD_CC
340 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
341 AC_TRY_LINK([#include <$qt_direct_test_header>],
342 $qt_direct_test_main,
345 # We can link with no special library directory.
348 # That did not work. Try the OpenGL version
349 echo "Non-critical error, please neglect the above." >&AC_FD_CC
351 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
352 AC_TRY_LINK([#include <$qt_direct_test_header>],
353 $qt_direct_test_main,
356 # We can link with no special library directory.
359 # That did not work. Maybe a library version I don't know about?
360 echo "Non-critical error, please neglect the above." >&AC_FD_CC
361 # Look for some Qt lib in a standard set of common directories.
363 `echo $bnv_qt_includes | sed ss/includess`
368 `ls -dr /usr/lib/qt* 2>/dev/null`
369 `ls -dr /usr/local/qt* 2>/dev/null`
370 `ls -dr /opt/qt* 2>/dev/null`
372 for bnv_dir in $bnv_dir_list; do
373 if ls $bnv_dir/libqt*; then
374 # Gamble that it's the first one...
375 bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p |
376 sed s@$bnv_dir/lib@@ | sed s/[.].*//`"
377 bnv_qt_lib_dir="$bnv_dir"
382 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
383 AC_TRY_LINK([#include <$qt_direct_test_header>],
384 $qt_direct_test_main,
387 # We can link with no special library directory.
390 # Leave bnv_qt_lib_dir defined
395 if test x"$bnv_qt_lib_dir" != x; then
396 bnv_qt_LIBS="-l$bnv_qt_lib_dir $LIBS"
400 LIBS="$bnv_save_LIBS"
401 CXXFLAGS="$bnv_save_CXXFLAGS"
402 fi dnl $with_Qt_lib_dir was not given
403 fi dnl Done setting up for non-traditional Trolltech installation