5
# (C) Copyright 2005-2007 EDF-EADS-Phimeca
7
# This library is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License.
12
# This library is distributed in the hope that it will be useful
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this library; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
# @author: $LastChangedBy: dutka $
22
# @date: $LastChangedDate: 2008-05-21 11:21:38 +0200 (mer, 21 mai 2008) $
23
# Id: $Id: bnv_have_qt.m4 815 2008-05-21 09:21:38Z dutka $
25
dnl @synopsis BNV_HAVE_QT [--with-Qt-dir=DIR] [--with-Qt-lib-dir=DIR] [--with-Qt-lib=LIB]
26
dnl @synopsis BNV_HAVE_QT [--with-Qt-include-dir=DIR] [--with-Qt-bin-dir=DIR] [--with-Qt-lib-dir=DIR] [--with-Qt-lib=LIB]
28
dnl @summary Search for Trolltech's Qt GUI framework.
30
dnl Searches common directories for Qt include files, libraries and Qt
31
dnl binary utilities. The macro supports several different versions of
32
dnl the Qt framework being installed on the same machine. Without
33
dnl options, the macro is designed to look for the latest library,
34
dnl i.e., the highest definition of QT_VERSION in qglobal.h. By use of
35
dnl one or more options a different library may be selected. There are
36
dnl two different sets of options. Both sets contain the option
37
dnl --with-Qt-lib=LIB which can be used to force the use of a
38
dnl particular version of the library file when more than one are
39
dnl available. LIB must be in the form as it would appear behind the
40
dnl "-l" option to the compiler. Examples for LIB would be "qt-mt" for
41
dnl the multi-threaded version and "qt" for the regular version. In
42
dnl addition to this, the first set consists of an option
43
dnl --with-Qt-dir=DIR which can be used when the installation conforms
44
dnl to Trolltech's standard installation, which means that header files
45
dnl are in DIR/include, binary utilities are in DIR/bin and the library
46
dnl is in DIR/lib. The second set of options can be used to indicate
47
dnl individual locations for the header files, the binary utilities and
48
dnl the library file, in addition to the specific version of the
51
dnl The following shell variable is set to either "yes" or "no":
55
dnl Additionally, the following variables are exported:
63
dnl which respectively contain an "-I" flag pointing to the Qt include
64
dnl directory (and "-DQT_THREAD_SUPPORT" when LIB is "qt-mt"), link
65
dnl flags necessary to link with Qt and X, the name of the meta object
66
dnl compiler and the user interface compiler both with full path, and
67
dnl finaly the variable QTDIR as Trolltech likes to see it defined (if
70
dnl Example lines for Makefile.in:
72
dnl CXXFLAGS = @QT_CXXFLAGS@
75
dnl After the variables have been set, a trial compile and link is
76
dnl performed to check the correct functioning of the meta object
77
dnl compiler. This test may fail when the different detected elements
78
dnl stem from different releases of the Qt framework. In that case, an
79
dnl error message is emitted and configure stops.
81
dnl No common variables such as $LIBS or $CFLAGS are polluted.
85
dnl --with-Qt-dir=DIR: DIR is equal to $QTDIR if you have followed the
86
dnl installation instructions of Trolltech. Header files are in
87
dnl DIR/include, binary utilities are in DIR/bin and the library is in
90
dnl --with-Qt-include-dir=DIR: Qt header files are in DIR.
92
dnl --with-Qt-bin-dir=DIR: Qt utilities such as moc and uic are in DIR.
94
dnl --with-Qt-lib-dir=DIR: The Qt library is in DIR.
96
dnl --with-Qt-lib=LIB: Use -lLIB to link with the Qt library.
98
dnl If some option "=no" or, equivalently, a --without-Qt-* version is
99
dnl given in stead of a --with-Qt-*, "have_qt" is set to "no" and the
100
dnl other variables are set to the empty string.
102
dnl @category InstalledPackages
103
dnl @author Bastiaan Veelo <Bastiaan@Veelo.net>
104
dnl @version 2006-03-12
105
dnl @license AllPermissive
107
dnl Copyright (C) 2001, 2002, 2003, 2005, 2006 Bastiaan Veelo
109
dnl THANKS! This code includes bug fixes and contributions made by:
111
dnl Dennis R. Weilert,
119
dnl 2006-03-12 * Hide output of ls and fix an m4 quoting problem (due to Scott J. Bertin).
120
dnl 2006-02-13 * Check compiler return value instead of parsing the error stream,
121
dnl which detected warnings as false negatives (due to Jens Hannemann).
122
dnl 2006-02-02 * Spelling of "Success".
123
dnl * Fixed unsave test for $bnv_qt_lib without quotes.
124
dnl * Put dnl in front of all comments.
125
dnl * Changed -l$bnv_qt_lib_dir into -L$bnv_qt_lib_dir (all due to Pavel Roskin).
126
dnl 2006-01-19 * Support for 64bit architectures.
127
dnl * Updated documentation.
128
dnl 2006-01-18: * Fix "cat: bnv_qt_test.c: No such file or directory" (due to Jens Hannemann).
129
dnl * Hide output of failing ls.
130
dnl 2006-01-11: * Check in /Developer on Mac OS X; Check in $QTDIR (due to Brian Mingus).
132
dnl Calls BNV_PATH_QT_DIRECT (contained in this file) as a subroutine.
133
AC_DEFUN([BNV_HAVE_QT],
135
AC_REQUIRE([AC_PROG_CXX])
136
AC_REQUIRE([AC_PATH_X])
137
AC_REQUIRE([AC_PATH_XTRA])
139
AC_MSG_CHECKING(for Qt)
141
AC_ARG_WITH([Qt-dir],
142
[ --with-Qt-dir=DIR DIR is equal to $QTDIR if you have followed the
143
installation instructions of Trolltech. Header
144
files are in DIR/include, binary utilities are
145
in DIR/bin. The library is in DIR/lib, unless
146
--with-Qt-lib-dir is also set.])
147
AC_ARG_WITH([Qt-include-dir],
148
[ --with-Qt-include-dir=DIR
149
Qt header files are in DIR])
150
AC_ARG_WITH([Qt-bin-dir],
151
[ --with-Qt-bin-dir=DIR Qt utilities such as moc and uic are in DIR])
152
AC_ARG_WITH([Qt-lib-dir],
153
[ --with-Qt-lib-dir=DIR The Qt library is in DIR])
154
AC_ARG_WITH([Qt-lib],
155
[ --with-Qt-lib=LIB Use -lLIB to link with the Qt library])
156
if test x"$with_Qt_dir" = x"no" ||
157
test x"$with_Qt_include-dir" = x"no" ||
158
test x"$with_Qt_bin_dir" = x"no" ||
159
test x"$with_Qt_lib_dir" = x"no" ||
160
test x"$with_Qt_lib" = x"no"; then
161
# user disabled Qt. Leave cache alone.
162
have_qt="User disabled Qt."
164
# "yes" is a bogus option
165
if test x"$with_Qt_dir" = xyes; then
168
if test x"$with_Qt_include_dir" = xyes; then
171
if test x"$with_Qt_bin_dir" = xyes; then
174
if test x"$with_Qt_lib_dir" = xyes; then
177
if test x"$with_Qt_lib" = xyes; then
180
# No Qt unless we discover otherwise
182
# Check whether we are requested to link with a specific version
183
if test x"$with_Qt_lib" != x; then
184
bnv_qt_lib="$with_Qt_lib"
186
# Check whether we were supplied with an answer already
187
if test x"$with_Qt_dir" != x; then
189
bnv_qt_dir="$with_Qt_dir"
190
bnv_qt_include_dir="$with_Qt_dir/include"
191
bnv_qt_bin_dir="$with_Qt_dir/bin"
192
bnv_qt_lib_dir="$with_Qt_dir/lib"
193
# Only search for the lib if the user did not define one already
194
if test x"$bnv_qt_lib" = x; then
195
bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
196
sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
198
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"
200
# Use cached value or do search, starting with suggestions from
202
AC_CACHE_VAL(bnv_cv_have_qt,
204
# We are not given a solution and there is no cached value.
206
bnv_qt_include_dir=NO
208
if test x"$bnv_qt_lib" = x; then
212
if test "$bnv_qt_dir" = NO ||
213
test "$bnv_qt_include_dir" = NO ||
214
test "$bnv_qt_lib_dir" = NO ||
215
test "$bnv_qt_lib" = NO; then
216
# Problem with finding complete Qt. Cache the known absence of Qt.
217
bnv_cv_have_qt="have_qt=no"
219
# Record where we found Qt for the cache.
220
bnv_cv_have_qt="have_qt=yes \
221
bnv_qt_dir=$bnv_qt_dir \
222
bnv_qt_include_dir=$bnv_qt_include_dir \
223
bnv_qt_bin_dir=$bnv_qt_bin_dir \
224
bnv_qt_LIBS=\"$bnv_qt_LIBS\""
227
eval "$bnv_cv_have_qt"
228
fi # all $bnv_qt_* are set
229
fi # $have_qt reflects the system status
230
if test x"$have_qt" = xyes; then
231
QT_CXXFLAGS="-I$bnv_qt_include_dir"
232
if test x"$bnv_qt_lib" = xqt-mt; then
233
QT_CXXFLAGS="$QT_CXXFLAGS -DQT_THREAD_SUPPORT"
236
QT_LIBS="$bnv_qt_LIBS"
237
# If bnv_qt_dir is defined, utilities are expected to be in the
239
if test x"$bnv_qt_dir" != x; then
240
if test -x "$bnv_qt_dir/bin/uic"; then
241
QT_UIC="$bnv_qt_dir/bin/uic"
243
# Old versions of Qt don't have uic
246
QT_MOC="$bnv_qt_dir/bin/moc"
248
# Or maybe we are told where to look for the utilities
249
if test x"$bnv_qt_bin_dir" != x; then
250
if test -x "$bnv_qt_bin_dir/uic"; then
251
QT_UIC="$bnv_qt_bin_dir/uic"
253
# Old versions of Qt don't have uic
256
QT_MOC="$bnv_qt_bin_dir/moc"
258
# Last possibility is that they are in $PATH
263
# All variables are defined, report the result
264
AC_MSG_RESULT([$have_qt:
265
QT_CXXFLAGS=$QT_CXXFLAGS
277
AC_MSG_RESULT($have_qt)
279
AC_SUBST(QT_CXXFLAGS)
286
if test x"$have_qt" = xyes; then
287
AC_MSG_CHECKING(correct functioning of Qt installation)
288
AC_CACHE_VAL(bnv_cv_qt_test_result,
290
cat > bnv_qt_test.h << EOF
292
class Test : public QObject
305
cat > bnv_qt_main.$ac_ext << EOF
306
#include "bnv_qt_test.h"
307
#include <qapplication.h>
308
int main( int argc, char **argv )
310
QApplication app( argc, argv );
312
QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) );
316
bnv_cv_qt_test_result="failure"
317
bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>/dev/null"
318
AC_TRY_EVAL(bnv_try_1)
319
if test x"$ac_status" != x0; then
320
echo "$bnv_err_1" >&AC_FD_CC
321
echo "configure: could not run $QT_MOC on:" >&AC_FD_CC
322
cat bnv_qt_test.h >&AC_FD_CC
324
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"
325
AC_TRY_EVAL(bnv_try_2)
326
if test x"$ac_status" != x0; then
327
echo "$bnv_err_2" >&AC_FD_CC
328
echo "configure: could not compile:" >&AC_FD_CC
329
cat moc_bnv_qt_test.$ac_ext >&AC_FD_CC
331
bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>/dev/null"
332
AC_TRY_EVAL(bnv_try_3)
333
if test x"$ac_status" != x0; then
334
echo "$bnv_err_3" >&AC_FD_CC
335
echo "configure: could not compile:" >&AC_FD_CC
336
cat bnv_qt_main.$ac_ext >&AC_FD_CC
338
bnv_try_4="$CXX $QT_LIBS $LIBS -o bnv_qt_main bnv_qt_main.o moc_bnv_qt_test.o $QT_LIBS>/dev/null 2>/dev/null"
339
AC_TRY_EVAL(bnv_try_4)
340
if test x"$ac_status" != x0; then
341
echo "$bnv_err_4" >&AC_FD_CC
343
bnv_cv_qt_test_result="success"
348
])dnl AC_CACHE_VAL bnv_cv_qt_test_result
349
AC_MSG_RESULT([$bnv_cv_qt_test_result]);
350
if test x"$bnv_cv_qt_test_result" = "xfailure"; then
351
AC_MSG_ERROR([Failed to find matching components of a complete
352
Qt installation. Try using more options,
353
see ./configure --help.])
356
rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \
357
bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main
361
dnl Internal subroutine of BNV_HAVE_QT
362
dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib
363
AC_DEFUN([BNV_PATH_QT_DIRECT],
365
## Binary utilities ##
366
if test x"$with_Qt_bin_dir" != x; then
367
bnv_qt_bin_dir=$with_Qt_bin_dir
369
## Look for header files ##
370
if test x"$with_Qt_include_dir" != x; then
371
bnv_qt_include_dir="$with_Qt_include_dir"
373
# The following header file is expected to define QT_VERSION.
374
qt_direct_test_header=qglobal.h
375
# Look for the header file in a standard set of common directories.
376
bnv_include_path_list="
378
`ls -dr ${QTDIR}/include 2>/dev/null`
379
`ls -dr /usr/include/qt* 2>/dev/null`
380
`ls -dr /usr/lib/qt*/include 2>/dev/null`
381
`ls -dr /usr/local/qt*/include 2>/dev/null`
382
`ls -dr /opt/qt*/include 2>/dev/null`
383
`ls -dr /Developer/qt*/include 2>/dev/null`
385
for bnv_dir in $bnv_include_path_list; do
386
if test -r "$bnv_dir/$qt_direct_test_header"; then
387
bnv_dirs="$bnv_dirs $bnv_dir"
390
# Now look for the newest in this list
392
for bnv_dir in $bnv_dirs; do
393
bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//`
394
if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then
395
bnv_qt_include_dir=$bnv_dir
396
bnv_prev_ver=$bnv_this_ver
399
fi dnl Found header files.
401
# Are these headers located in a traditional Trolltech installation?
402
# That would be $bnv_qt_include_dir stripped from its last element:
403
bnv_possible_qt_dir=`dirname $bnv_qt_include_dir`
404
if (test -x $bnv_possible_qt_dir/bin/moc) &&
405
((ls $bnv_possible_qt_dir/lib/libqt* > /dev/null 2>/dev/null) ||
406
(ls $bnv_possible_qt_dir/lib64/libqt* > /dev/null 2>/dev/null)); then
407
# Then the rest is a piece of cake
408
bnv_qt_dir=$bnv_possible_qt_dir
409
bnv_qt_bin_dir="$bnv_qt_dir/bin"
410
if test x"$with_Qt_lib_dir" != x; then
411
bnv_qt_lib_dir="$with_Qt_lib_dir"
413
if (test -d $bnv_qt_dir/lib64); then
414
bnv_qt_lib_dir="$bnv_qt_dir/lib64"
416
bnv_qt_lib_dir="$bnv_qt_dir/lib"
419
# Only look for lib if the user did not supply it already
420
if test x"$bnv_qt_lib" = xNO; then
421
bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
422
sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
424
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"
426
# There is no valid definition for $QTDIR as Trolltech likes to see it
428
## Look for Qt library ##
429
if test x"$with_Qt_lib_dir" != x; then
430
bnv_qt_lib_dir="$with_Qt_lib_dir"
431
# Only look for lib if the user did not supply it already
432
if test x"$bnv_qt_lib" = xNO; then
433
bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
434
sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
436
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"
438
# Normally, when there is no traditional Trolltech installation,
439
# the library is installed in a place where the linker finds it
441
# If the user did not define the library name, try with qt
442
if test x"$bnv_qt_lib" = xNO; then
445
qt_direct_test_header=qapplication.h
446
qt_direct_test_main="
449
QApplication app(argc,argv);
451
# See if we find the library without any special options.
452
# Don't add top $LIBS permanently yet
453
bnv_save_LIBS="$LIBS"
454
LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
456
bnv_save_CXXFLAGS="$CXXFLAGS"
457
CXXFLAGS="-I$bnv_qt_include_dir"
458
AC_TRY_LINK([#include <$qt_direct_test_header>],
459
$qt_direct_test_main,
462
# We can link with no special library directory.
465
# That did not work. Try the multi-threaded version
466
echo "Non-critical error, please neglect the above." >&AC_FD_CC
468
LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
469
AC_TRY_LINK([#include <$qt_direct_test_header>],
470
$qt_direct_test_main,
473
# We can link with no special library directory.
476
# That did not work. Try the OpenGL version
477
echo "Non-critical error, please neglect the above." >&AC_FD_CC
479
LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
480
AC_TRY_LINK([#include <$qt_direct_test_header>],
481
$qt_direct_test_main,
484
# We can link with no special library directory.
487
# That did not work. Maybe a library version I don't know about?
488
echo "Non-critical error, please neglect the above." >&AC_FD_CC
489
# Look for some Qt lib in a standard set of common directories.
491
`echo $bnv_qt_includes | sed ss/includess`
499
`ls -dr /usr/lib64/qt* 2>/dev/null`
500
`ls -dr /usr/lib64/qt*/lib64 2>/dev/null`
501
`ls -dr /usr/lib/qt* 2>/dev/null`
502
`ls -dr /usr/local/qt* 2>/dev/null`
503
`ls -dr /opt/qt* 2>/dev/null`
505
for bnv_dir in $bnv_dir_list; do
506
if ls $bnv_dir/libqt* >/dev/null 2>/dev/null; then
507
# Gamble that it's the first one...
508
bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p |
509
sed s@$bnv_dir/lib@@ | sed s/[[.]].*//`"
510
bnv_qt_lib_dir="$bnv_dir"
515
LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
516
AC_TRY_LINK([#include <$qt_direct_test_header>],
517
$qt_direct_test_main,
520
# We can link with no special library directory.
523
# Leave bnv_qt_lib_dir defined
528
if test x"$bnv_qt_lib_dir" != x; then
529
bnv_qt_LIBS="-L$bnv_qt_lib_dir $LIBS"
533
LIBS="$bnv_save_LIBS"
534
CXXFLAGS="$bnv_save_CXXFLAGS"
535
fi dnl $with_Qt_lib_dir was not given
536
fi dnl Done setting up for non-traditional Trolltech installation