1 dnl Copyright (C) 2001, 2002, 2003, 2005, 2006 Bastiaan Veelo
3 dnl THANKS! This code includes bug fixes and contributions made by:
13 dnl 2006-03-12 * Hide output of ls and fix an m4 quoting problem (due to Scott J. Bertin).
14 dnl 2006-02-13 * Check compiler return value instead of parsing the error stream,
15 dnl which detected warnings as false negatives (due to Jens Hannemann).
16 dnl 2006-02-02 * Spelling of "Success".
17 dnl * Fixed unsave test for $bnv_qt_lib without quotes.
18 dnl * Put dnl in front of all comments.
19 dnl * Changed -l$bnv_qt_lib_dir into -L$bnv_qt_lib_dir (all due to Pavel Roskin).
20 dnl 2006-01-19 * Support for 64bit architectures.
21 dnl * Updated documentation.
22 dnl 2006-01-18: * Fix "cat: bnv_qt_test.c: No such file or directory" (due to Jens Hannemann).
23 dnl * Hide output of failing ls.
24 dnl 2006-01-11: * Check in /Developer on Mac OS X; Check in $QTDIR (due to Brian Mingus).
26 dnl Calls BNV_PATH_QT_DIRECT (contained in this file) as a subroutine.
27 AC_DEFUN([BNV_HAVE_QT],
29 AC_REQUIRE([AC_PROG_CXX])
30 AC_REQUIRE([AC_PATH_X])
31 AC_REQUIRE([AC_PATH_XTRA])
33 AC_MSG_CHECKING(for Qt)
36 [ --with-Qt-dir=DIR DIR is equal to $QTDIR if you have followed the
37 installation instructions of Trolltech. Header
38 files are in DIR/include, binary utilities are
39 in DIR/bin. The library is in DIR/lib, unless
40 --with-Qt-lib-dir is also set.])
41 AC_ARG_WITH([Qt-include-dir],
42 [ --with-Qt-include-dir=DIR
43 Qt header files are in DIR])
44 AC_ARG_WITH([Qt-bin-dir],
45 [ --with-Qt-bin-dir=DIR Qt utilities such as moc and uic are in DIR])
46 AC_ARG_WITH([Qt-lib-dir],
47 [ --with-Qt-lib-dir=DIR The Qt library is in DIR])
49 [ --with-Qt-lib=LIB Use -lLIB to link with the Qt library])
50 if test x"$with_Qt_dir" = x"no" ||
51 test x"$with_Qt_include-dir" = x"no" ||
52 test x"$with_Qt_bin_dir" = x"no" ||
53 test x"$with_Qt_lib_dir" = x"no" ||
54 test x"$with_Qt_lib" = x"no"; then
55 # user disabled Qt. Leave cache alone.
56 have_qt="User disabled Qt."
58 # "yes" is a bogus option
59 if test x"$with_Qt_dir" = xyes; then
62 if test x"$with_Qt_include_dir" = xyes; then
65 if test x"$with_Qt_bin_dir" = xyes; then
68 if test x"$with_Qt_lib_dir" = xyes; then
71 if test x"$with_Qt_lib" = xyes; then
74 # No Qt unless we discover otherwise
76 # Check whether we are requested to link with a specific version
77 if test x"$with_Qt_lib" != x; then
78 bnv_qt_lib="$with_Qt_lib"
80 # Check whether we were supplied with an answer already
81 if test x"$with_Qt_dir" != x; then
83 bnv_qt_dir="$with_Qt_dir"
84 bnv_qt_include_dir="$with_Qt_dir/include"
85 bnv_qt_bin_dir="$with_Qt_dir/bin"
86 bnv_qt_lib_dir="$with_Qt_dir/lib"
87 # Only search for the lib if the user did not define one already
88 if test x"$bnv_qt_lib" = x; then
89 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
90 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
92 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"
94 # Use cached value or do search, starting with suggestions from
96 AC_CACHE_VAL(bnv_cv_have_qt,
98 # We are not given a solution and there is no cached value.
100 bnv_qt_include_dir=NO
102 if test x"$bnv_qt_lib" = x; then
106 if test "$bnv_qt_dir" = NO ||
107 test "$bnv_qt_include_dir" = NO ||
108 test "$bnv_qt_lib_dir" = NO ||
109 test "$bnv_qt_lib" = NO; then
110 # Problem with finding complete Qt. Cache the known absence of Qt.
111 bnv_cv_have_qt="have_qt=no"
113 # Record where we found Qt for the cache.
114 bnv_cv_have_qt="have_qt=yes \
115 bnv_qt_dir=$bnv_qt_dir \
116 bnv_qt_include_dir=$bnv_qt_include_dir \
117 bnv_qt_bin_dir=$bnv_qt_bin_dir \
118 bnv_qt_LIBS=\"$bnv_qt_LIBS\""
121 eval "$bnv_cv_have_qt"
122 fi # all $bnv_qt_* are set
123 fi # $have_qt reflects the system status
124 if test x"$have_qt" = xyes; then
125 QT_CXXFLAGS="-I$bnv_qt_include_dir"
126 if test x"$bnv_qt_lib" = xqt-mt; then
127 QT_CXXFLAGS="$QT_CXXFLAGS -DQT_THREAD_SUPPORT"
130 QT_LIBS="$bnv_qt_LIBS"
131 # If bnv_qt_dir is defined, utilities are expected to be in the
133 if test x"$bnv_qt_dir" != x; then
134 if test -x "$bnv_qt_dir/bin/uic"; then
135 QT_UIC="$bnv_qt_dir/bin/uic"
137 # Old versions of Qt don't have uic
140 QT_MOC="$bnv_qt_dir/bin/moc"
142 # Or maybe we are told where to look for the utilities
143 if test x"$bnv_qt_bin_dir" != x; then
144 if test -x "$bnv_qt_bin_dir/uic"; then
145 QT_UIC="$bnv_qt_bin_dir/uic"
147 # Old versions of Qt don't have uic
150 QT_MOC="$bnv_qt_bin_dir/moc"
152 # Last possibility is that they are in $PATH
157 # All variables are defined, report the result
158 AC_MSG_RESULT([$have_qt:
159 QT_CXXFLAGS=$QT_CXXFLAGS
171 AC_MSG_RESULT($have_qt)
173 AC_SUBST(QT_CXXFLAGS)
180 if test x"$have_qt" = xyes; then
181 AC_MSG_CHECKING(correct functioning of Qt installation)
182 AC_CACHE_VAL(bnv_cv_qt_test_result,
184 cat > bnv_qt_test.h << EOF
186 class Test : public QObject
199 cat > bnv_qt_main.$ac_ext << EOF
200 #include "bnv_qt_test.h"
201 #include <qapplication.h>
202 int main( int argc, char **argv )
204 QApplication app( argc, argv );
206 QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) );
210 bnv_cv_qt_test_result="failure"
211 bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>/dev/null"
212 AC_TRY_EVAL(bnv_try_1)
213 if test x"$ac_status" != x0; then
214 echo "$bnv_err_1" >&AC_FD_CC
215 echo "configure: could not run $QT_MOC on:" >&AC_FD_CC
216 cat bnv_qt_test.h >&AC_FD_CC
218 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"
219 AC_TRY_EVAL(bnv_try_2)
220 if test x"$ac_status" != x0; then
221 echo "$bnv_err_2" >&AC_FD_CC
222 echo "configure: could not compile:" >&AC_FD_CC
223 cat moc_bnv_qt_test.$ac_ext >&AC_FD_CC
225 bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>/dev/null"
226 AC_TRY_EVAL(bnv_try_3)
227 if test x"$ac_status" != x0; then
228 echo "$bnv_err_3" >&AC_FD_CC
229 echo "configure: could not compile:" >&AC_FD_CC
230 cat bnv_qt_main.$ac_ext >&AC_FD_CC
232 bnv_try_4="$CXX $LIBS -o bnv_qt_main bnv_qt_main.o moc_bnv_qt_test.o $QT_LIBS >/dev/null 2>/dev/null"
233 AC_TRY_EVAL(bnv_try_4)
234 if test x"$ac_status" != x0; then
235 echo "$bnv_err_4" >&AC_FD_CC
237 bnv_cv_qt_test_result="success"
242 ])dnl AC_CACHE_VAL bnv_cv_qt_test_result
243 AC_MSG_RESULT([$bnv_cv_qt_test_result]);
244 if test x"$bnv_cv_qt_test_result" = "xfailure"; then
245 AC_MSG_ERROR([Failed to find matching components of a complete
246 Qt installation. Try using more options,
247 see ./configure --help.])
250 rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \
251 bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main
255 dnl Internal subroutine of BNV_HAVE_QT
256 dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib
257 AC_DEFUN([BNV_PATH_QT_DIRECT],
259 ## Binary utilities ##
260 if test x"$with_Qt_bin_dir" != x; then
261 bnv_qt_bin_dir=$with_Qt_bin_dir
263 ## Look for header files ##
264 if test x"$with_Qt_include_dir" != x; then
265 bnv_qt_include_dir="$with_Qt_include_dir"
267 # The following header file is expected to define QT_VERSION.
268 qt_direct_test_header=qglobal.h
269 # Look for the header file in a standard set of common directories.
270 bnv_include_path_list="
272 `ls -dr ${QTDIR}/include 2>/dev/null`
273 `ls -dr /usr/include/qt* 2>/dev/null`
274 `ls -dr /usr/lib/qt*/include 2>/dev/null`
275 `ls -dr /usr/local/qt*/include 2>/dev/null`
276 `ls -dr /opt/qt*/include 2>/dev/null`
277 `ls -dr /Developer/qt*/include 2>/dev/null`
279 for bnv_dir in $bnv_include_path_list; do
280 if test -r "$bnv_dir/$qt_direct_test_header"; then
281 bnv_dirs="$bnv_dirs $bnv_dir"
284 # Now look for the newest in this list
286 for bnv_dir in $bnv_dirs; do
287 bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//`
288 if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then
289 bnv_qt_include_dir=$bnv_dir
290 bnv_prev_ver=$bnv_this_ver
293 fi dnl Found header files.
295 # Are these headers located in a traditional Trolltech installation?
296 # That would be $bnv_qt_include_dir stripped from its last element:
297 bnv_possible_qt_dir=`dirname $bnv_qt_include_dir`
298 if (test -x $bnv_possible_qt_dir/bin/moc) &&
299 ((ls $bnv_possible_qt_dir/lib/libqt* > /dev/null 2>/dev/null) ||
300 (ls $bnv_possible_qt_dir/lib64/libqt* > /dev/null 2>/dev/null)); then
301 # Then the rest is a piece of cake
302 bnv_qt_dir=$bnv_possible_qt_dir
303 bnv_qt_bin_dir="$bnv_qt_dir/bin"
304 if test x"$with_Qt_lib_dir" != x; then
305 bnv_qt_lib_dir="$with_Qt_lib_dir"
307 if (test -d $bnv_qt_dir/lib64); then
308 bnv_qt_lib_dir="$bnv_qt_dir/lib64"
310 bnv_qt_lib_dir="$bnv_qt_dir/lib"
313 # Only look for lib if the user did not supply it already
314 if test x"$bnv_qt_lib" = xNO; then
315 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
316 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
318 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"
320 # There is no valid definition for $QTDIR as Trolltech likes to see it
322 ## Look for Qt library ##
323 if test x"$with_Qt_lib_dir" != x; then
324 bnv_qt_lib_dir="$with_Qt_lib_dir"
325 # Only look for lib if the user did not supply it already
326 if test x"$bnv_qt_lib" = xNO; then
327 bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
328 sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
330 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"
332 # Normally, when there is no traditional Trolltech installation,
333 # the library is installed in a place where the linker finds it
335 # If the user did not define the library name, try with qt
336 if test x"$bnv_qt_lib" = xNO; then
339 qt_direct_test_header=qapplication.h
340 qt_direct_test_main="
343 QApplication app(argc,argv);
345 # See if we find the library without any special options.
346 # Don't add top $LIBS permanently yet
347 bnv_save_LIBS="$LIBS"
348 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
350 bnv_save_CXXFLAGS="$CXXFLAGS"
351 CXXFLAGS="-I$bnv_qt_include_dir"
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. Try the multi-threaded version
360 echo "Non-critical error, please neglect the above." >&AC_FD_CC
362 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
363 AC_TRY_LINK([#include <$qt_direct_test_header>],
364 $qt_direct_test_main,
367 # We can link with no special library directory.
370 # That did not work. Try the OpenGL version
371 echo "Non-critical error, please neglect the above." >&AC_FD_CC
373 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
374 AC_TRY_LINK([#include <$qt_direct_test_header>],
375 $qt_direct_test_main,
378 # We can link with no special library directory.
381 # That did not work. Maybe a library version I don't know about?
382 echo "Non-critical error, please neglect the above." >&AC_FD_CC
383 # Look for some Qt lib in a standard set of common directories.
385 `echo $bnv_qt_includes | sed ss/includess`
393 `ls -dr /usr/lib64/qt* 2>/dev/null`
394 `ls -dr /usr/lib64/qt*/lib64 2>/dev/null`
395 `ls -dr /usr/lib/qt* 2>/dev/null`
396 `ls -dr /usr/local/qt* 2>/dev/null`
397 `ls -dr /opt/qt* 2>/dev/null`
399 for bnv_dir in $bnv_dir_list; do
400 if ls $bnv_dir/libqt* >/dev/null 2>/dev/null; then
401 # Gamble that it's the first one...
402 bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p |
403 sed s@$bnv_dir/lib@@ | sed s/[[.]].*//`"
404 bnv_qt_lib_dir="$bnv_dir"
409 LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
410 AC_TRY_LINK([#include <$qt_direct_test_header>],
411 $qt_direct_test_main,
414 # We can link with no special library directory.
417 # Leave bnv_qt_lib_dir defined
422 if test x"$bnv_qt_lib_dir" != x; then
423 bnv_qt_LIBS="-L$bnv_qt_lib_dir $LIBS"
427 LIBS="$bnv_save_LIBS"
428 CXXFLAGS="$bnv_save_CXXFLAGS"
429 fi dnl $with_Qt_lib_dir was not given
430 fi dnl Done setting up for non-traditional Trolltech installation