Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/qt_gui/acinclude.m4 @ 7318

Last change on this file since 7318 was 7142, checked in by bensch, 19 years ago

orxonox/qt_gui: compiling the QT-app

File size: 16.9 KB
Line 
1
2
3dnl AX_CHECK_HEADER_LIB([HEADER-NAME], [LIBRARY-NAME], [FUNCTION-IN-LIB], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], [LIB-WEB-PAGE])
4AC_DEFUN([AX_CHECK_HEADER_LIB], [
5    _header_check=""
6    _lib_check=""
7
8    AC_CHECK_HEADER([$1], [_header_check="yes"], [_header_check="no"])
9    AC_CHECK_LIB([$2], [$3], [_lib_check="yes"], [_lib_check="no"])
10    if [test "x$_header_check" = "xyes" && test "x$_lib_check" = "xyes"] ; then
11         LIBS="$LIBS -l$2"
12         $4
13    else
14         echo "no Support for $2"
15         $5
16    fi
17])
18
19
20
21dnl AX_CHECK_REQUIRED_HEADER_LIB([HEADER-NAME], [LIBRARY-NAME], [FUNCTION-IN-LIB], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], [LIB-WEB-PAGE])
22AC_DEFUN([AX_CHECK_REQUIRED_HEADER_LIB], [
23    _header_check=""
24    _lib_check=""
25
26    for _header in $1
27    do
28      AC_CHECK_HEADER([$_header], [_header_check="yes"], [_header_check="no"])
29      if  test "x$_header_check" = "xyes" ; then
30        break
31      fi
32    done
33    AC_CHECK_LIB([$2], [$3], [_lib_check="yes"], [_lib_check="no"])
34    if [test x$_header_check = "xyes" && test "x$_lib_check" = "xyes"] ; then
35         LIBS="$LIBS -l$2"
36         $4
37    else
38         echo "------------------"
39         echo "LIBRARY $2 not found."
40         echo "please install the $2-LIBRARY-package which can be found at $6"
41         echo "------------------"
42         $5
43         exit -1
44    fi
45])
46
47
48
49dnl AX_CHECK_REQUIRED_LIB([LIBRARY-NAME], [FUNCTION-IN-LIB], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], [LIB-WEB-PAGE])
50AC_DEFUN([AX_CHECK_REQUIRED_LIB], [
51    _lib_check=""
52    _found_lib=""
53
54
55    for _lib in $1
56    do
57      AC_CHECK_LIB([$_lib], [$2], [_lib_check="yes"], [_lib_check="no"])
58      if test "x$_lib_check" = "xyes" ; then
59        _found_lib=$_lib
60        break
61      fi
62    done
63
64    if [test "x$_lib_check" = "xyes"] ; then
65         LIBS="$LIBS -l$_found_lib"
66         $3
67    else
68         echo "------------------"
69         echo "LIBRARY $1 not found."
70         echo "please install the $1-LIBRARY-package which can be found at $5"
71         echo "------------------"
72         $4
73         exit -1
74    fi
75])
76
77
78
79
80dnl Copyright (C) 2001, 2002, 2003, 2005, 2006 Bastiaan Veelo
81
82dnl THANKS! This code includes bug fixes and contributions made by:
83dnl Tim McClarren,
84dnl Dennis R. Weilert,
85dnl Qingning Huo,
86dnl Brian Mingus,
87dnl Jens Hannemann,
88dnl Pavel Roskin.
89
90dnl ChangeLog
91dnl 2006-02-13  * Check compiler return value instead of parsing the error stream,
92dnl               which detected warnings as false negatives (due to Jens Hannemann).
93dnl 2006-02-02  * Spelling of "Success".
94dnl             * Fixed unsave test for $bnv_qt_lib without quotes.
95dnl             * Put dnl in front of all comments.
96dnl             * Changed -l$bnv_qt_lib_dir into -L$bnv_qt_lib_dir (all due to Pavel Roskin).
97dnl 2006-01-19  * Support for 64bit architectures.
98dnl             * Updated documentation.
99dnl 2006-01-18: * Fix "cat: bnv_qt_test.c: No such file or directory" (due to Jens Hannemann).
100dnl             * Hide output of failing ls.
101dnl 2006-01-11: * Check in /Developer on Mac OS X; Check in $QTDIR (due to Brian Mingus).
102
103dnl Calls BNV_PATH_QT_DIRECT (contained in this file) as a subroutine.
104AC_DEFUN([BNV_HAVE_QT],
105[
106  AC_REQUIRE([AC_PROG_CXX])
107  AC_REQUIRE([AC_PATH_X])
108  AC_REQUIRE([AC_PATH_XTRA])
109
110  AC_MSG_CHECKING(for Qt)
111
112  AC_ARG_WITH([Qt-dir],
113    [  --with-Qt-dir=DIR       DIR is equal to $QTDIR if you have followed the
114                          installation instructions of Trolltech. Header
115                          files are in DIR/include, binary utilities are
116                          in DIR/bin. The library is in DIR/lib, unless
117                          --with-Qt-lib-dir is also set.])
118  AC_ARG_WITH([Qt-include-dir],
119    [  --with-Qt-include-dir=DIR
120                          Qt header files are in DIR])
121  AC_ARG_WITH([Qt-bin-dir],
122    [  --with-Qt-bin-dir=DIR   Qt utilities such as moc and uic are in DIR])
123  AC_ARG_WITH([Qt-lib-dir],
124    [  --with-Qt-lib-dir=DIR   The Qt library is in DIR])
125  AC_ARG_WITH([Qt-lib],
126    [  --with-Qt-lib=LIB       Use -lLIB to link with the Qt library])
127  if test x"$with_Qt_dir" = x"no" ||
128     test x"$with_Qt_include-dir" = x"no" ||
129     test x"$with_Qt_bin_dir" = x"no" ||
130     test x"$with_Qt_lib_dir" = x"no" ||
131     test x"$with_Qt_lib" = x"no"; then
132# user disabled Qt. Leave cache alone.
133    have_qt="User disabled Qt."
134  else
135# "yes" is a bogus option
136    if test x"$with_Qt_dir" = xyes; then
137      with_Qt_dir=
138    fi
139    if test x"$with_Qt_include_dir" = xyes; then
140      with_Qt_include_dir=
141    fi
142    if test x"$with_Qt_bin_dir" = xyes; then
143      with_Qt_bin_dir=
144    fi
145    if test x"$with_Qt_lib_dir" = xyes; then
146      with_Qt_lib_dir=
147    fi
148    if test x"$with_Qt_lib" = xyes; then
149      with_Qt_lib=
150    fi
151# No Qt unless we discover otherwise
152    have_qt=no
153# Check whether we are requested to link with a specific version
154    if test x"$with_Qt_lib" != x; then
155      bnv_qt_lib="$with_Qt_lib"
156    fi
157# Check whether we were supplied with an answer already
158    if test x"$with_Qt_dir" != x; then
159      have_qt=yes
160      bnv_qt_dir="$with_Qt_dir"
161      bnv_qt_include_dir="$with_Qt_dir/include"
162      bnv_qt_bin_dir="$with_Qt_dir/bin"
163      bnv_qt_lib_dir="$with_Qt_dir/lib"
164# Only search for the lib if the user did not define one already
165      if test x"$bnv_qt_lib" = x; then
166        bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
167                     sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
168      fi
169      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"
170    else
171# Use cached value or do search, starting with suggestions from
172# the command line
173      AC_CACHE_VAL(bnv_cv_have_qt,
174      [
175# We are not given a solution and there is no cached value.
176        bnv_qt_dir=NO
177        bnv_qt_include_dir=NO
178        bnv_qt_lib_dir=NO
179        if test x"$bnv_qt_lib" = x; then
180          bnv_qt_lib=NO
181        fi
182        BNV_PATH_QT_DIRECT
183        if test "$bnv_qt_dir" = NO ||
184           test "$bnv_qt_include_dir" = NO ||
185           test "$bnv_qt_lib_dir" = NO ||
186           test "$bnv_qt_lib" = NO; then
187# Problem with finding complete Qt.  Cache the known absence of Qt.
188          bnv_cv_have_qt="have_qt=no"
189        else
190# Record where we found Qt for the cache.
191          bnv_cv_have_qt="have_qt=yes                  \
192                       bnv_qt_dir=$bnv_qt_dir          \
193               bnv_qt_include_dir=$bnv_qt_include_dir  \
194                   bnv_qt_bin_dir=$bnv_qt_bin_dir      \
195                      bnv_qt_LIBS=\"$bnv_qt_LIBS\""
196        fi
197      ])dnl
198      eval "$bnv_cv_have_qt"
199    fi # all $bnv_qt_* are set
200  fi   # $have_qt reflects the system status
201  if test x"$have_qt" = xyes; then
202    QT_CXXFLAGS="-I$bnv_qt_include_dir"
203    if test x"$bnv_qt_lib" = xqt-mt; then
204        QT_CXXFLAGS="$QT_CXXFLAGS -DQT_THREAD_SUPPORT"
205    fi
206    QT_DIR="$bnv_qt_dir"
207    QT_LIBS="$bnv_qt_LIBS"
208# If bnv_qt_dir is defined, utilities are expected to be in the
209# bin subdirectory
210    if test x"$bnv_qt_dir" != x; then
211        if test -x "$bnv_qt_dir/bin/uic"; then
212          QT_UIC="$bnv_qt_dir/bin/uic"
213        else
214# Old versions of Qt don't have uic
215          QT_UIC=
216        fi
217      QT_MOC="$bnv_qt_dir/bin/moc"
218    else
219# Or maybe we are told where to look for the utilities
220      if test x"$bnv_qt_bin_dir" != x; then
221        if test -x "$bnv_qt_bin_dir/uic"; then
222          QT_UIC="$bnv_qt_bin_dir/uic"
223        else
224# Old versions of Qt don't have uic
225          QT_UIC=
226        fi
227        QT_MOC="$bnv_qt_bin_dir/moc"
228      else
229# Last possibility is that they are in $PATH
230        QT_UIC="`which uic`"
231        QT_MOC="`which moc`"
232      fi
233    fi
234# All variables are defined, report the result
235    AC_MSG_RESULT([$have_qt:
236    QT_CXXFLAGS=$QT_CXXFLAGS
237    QT_DIR=$QT_DIR
238    QT_LIBS=$QT_LIBS
239    QT_UIC=$QT_UIC
240    QT_MOC=$QT_MOC])
241  else
242# Qt was not found
243    QT_CXXFLAGS=
244    QT_DIR=
245    QT_LIBS=
246    QT_UIC=
247    QT_MOC=
248    AC_MSG_RESULT($have_qt)
249  fi
250  AC_SUBST(QT_CXXFLAGS)
251  AC_SUBST(QT_DIR)
252  AC_SUBST(QT_LIBS)
253  AC_SUBST(QT_UIC)
254  AC_SUBST(QT_MOC)
255
256#### Being paranoid:
257  if test x"$have_qt" = xyes; then
258    AC_MSG_CHECKING(correct functioning of Qt installation)
259    AC_CACHE_VAL(bnv_cv_qt_test_result,
260    [
261      cat > bnv_qt_test.h << EOF
262#include <qobject.h>
263class Test : public QObject
264{
265Q_OBJECT
266  public:
267  Test() {}
268  ~Test() {}
269  public slots:
270  void receive() {}
271  signals:
272  void send();
273};
274EOF
275
276      cat > bnv_qt_main.$ac_ext << EOF
277#include "bnv_qt_test.h"
278#include <qapplication.h>
279int main( int argc, char **argv )
280{
281  QApplication app( argc, argv );
282  Test t;
283  QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) );
284}
285EOF
286
287      bnv_cv_qt_test_result="failure"
288      bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>/dev/null"
289      AC_TRY_EVAL(bnv_try_1)
290      if test x"$ac_status" != x0; then
291        echo "$bnv_err_1" >&AC_FD_CC
292        echo "configure: could not run $QT_MOC on:" >&AC_FD_CC
293        cat bnv_qt_test.h >&AC_FD_CC
294      else
295        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"
296        AC_TRY_EVAL(bnv_try_2)
297        if test x"$ac_status" != x0; then
298          echo "$bnv_err_2" >&AC_FD_CC
299          echo "configure: could not compile:" >&AC_FD_CC
300          cat moc_bnv_qt_test.$ac_ext >&AC_FD_CC
301        else
302          bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>/dev/null"
303          AC_TRY_EVAL(bnv_try_3)
304          if test x"$ac_status" != x0; then
305            echo "$bnv_err_3" >&AC_FD_CC
306            echo "configure: could not compile:" >&AC_FD_CC
307            cat bnv_qt_main.$ac_ext >&AC_FD_CC
308          else
309            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"
310            AC_TRY_EVAL(bnv_try_4)
311            if test x"$ac_status" != x0; then
312              echo "$bnv_err_4" >&AC_FD_CC
313            else
314              bnv_cv_qt_test_result="success"
315            fi
316          fi
317        fi
318      fi
319    ])dnl AC_CACHE_VAL bnv_cv_qt_test_result
320    AC_MSG_RESULT([$bnv_cv_qt_test_result]);
321    if test x"$bnv_cv_qt_test_result" = "xfailure"; then
322      AC_MSG_ERROR([Failed to find matching components of a complete
323                  Qt installation. Try using more options,
324                  see ./configure --help.])
325    fi
326
327    rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \
328          bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main
329  fi
330])
331
332dnl Internal subroutine of BNV_HAVE_QT
333dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib
334AC_DEFUN([BNV_PATH_QT_DIRECT],
335[
336## Binary utilities ##
337  if test x"$with_Qt_bin_dir" != x; then
338    bnv_qt_bin_dir=$with_Qt_bin_dir
339  fi
340## Look for header files ##
341  if test x"$with_Qt_include_dir" != x; then
342    bnv_qt_include_dir="$with_Qt_include_dir"
343  else
344# The following header file is expected to define QT_VERSION.
345    qt_direct_test_header=qglobal.h
346# Look for the header file in a standard set of common directories.
347    bnv_include_path_list="
348      /usr/include
349      `ls -dr ${QTDIR}/include 2>/dev/null`
350      `ls -dr /usr/include/qt* 2>/dev/null`
351      `ls -dr /usr/lib/qt*/include 2>/dev/null`
352      `ls -dr /usr/local/qt*/include 2>/dev/null`
353      `ls -dr /opt/qt*/include 2>/dev/null`
354      `ls -dr /Developer/qt*/include 2>/dev/null`
355    "
356    for bnv_dir in $bnv_include_path_list; do
357      if test -r "$bnv_dir/$qt_direct_test_header"; then
358        bnv_dirs="$bnv_dirs $bnv_dir"
359      fi
360    done
361# Now look for the newest in this list
362    bnv_prev_ver=0
363    for bnv_dir in $bnv_dirs; do
364      bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//`
365      if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then
366        bnv_qt_include_dir=$bnv_dir
367        bnv_prev_ver=$bnv_this_ver
368      fi
369    done
370  fi dnl Found header files.
371
372# Are these headers located in a traditional Trolltech installation?
373# That would be $bnv_qt_include_dir stripped from its last element:
374  bnv_possible_qt_dir=`dirname $bnv_qt_include_dir`
375  if (test -x $bnv_possible_qt_dir/bin/moc) &&
376     ((ls $bnv_possible_qt_dir/lib/libqt* > /dev/null 2>/dev/null) ||
377      (ls $bnv_possible_qt_dir/lib64/libqt* > /dev/null 2>/dev/null)); then
378# Then the rest is a piece of cake
379    bnv_qt_dir=$bnv_possible_qt_dir
380    bnv_qt_bin_dir="$bnv_qt_dir/bin"
381    if test x"$with_Qt_lib_dir" != x; then
382      bnv_qt_lib_dir="$with_Qt_lib_dir"
383    else
384      if (test -d $bnv_qt_dir/lib64); then
385        bnv_qt_lib_dir="$bnv_qt_dir/lib64"
386      else
387        bnv_qt_lib_dir="$bnv_qt_dir/lib"
388      fi
389    fi
390# Only look for lib if the user did not supply it already
391    if test x"$bnv_qt_lib" = xNO; then
392      bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
393                   sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
394    fi
395    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"
396  else
397# There is no valid definition for $QTDIR as Trolltech likes to see it
398    bnv_qt_dir=
399## Look for Qt library ##
400    if test x"$with_Qt_lib_dir" != x; then
401      bnv_qt_lib_dir="$with_Qt_lib_dir"
402# Only look for lib if the user did not supply it already
403      if test x"$bnv_qt_lib" = xNO; then
404        bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p |
405                     sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`"
406      fi
407      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"
408    else
409# Normally, when there is no traditional Trolltech installation,
410# the library is installed in a place where the linker finds it
411# automatically.
412# If the user did not define the library name, try with qt
413      if test x"$bnv_qt_lib" = xNO; then
414        bnv_qt_lib=qt
415      fi
416      qt_direct_test_header=qapplication.h
417      qt_direct_test_main="
418        int argc;
419        char ** argv;
420        QApplication app(argc,argv);
421      "
422# See if we find the library without any special options.
423# Don't add top $LIBS permanently yet
424      bnv_save_LIBS="$LIBS"
425      LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
426      bnv_qt_LIBS="$LIBS"
427      bnv_save_CXXFLAGS="$CXXFLAGS"
428      CXXFLAGS="-I$bnv_qt_include_dir"
429      AC_TRY_LINK([#include <$qt_direct_test_header>],
430        $qt_direct_test_main,
431      [
432# Success.
433# We can link with no special library directory.
434        bnv_qt_lib_dir=
435      ], [
436# That did not work. Try the multi-threaded version
437        echo "Non-critical error, please neglect the above." >&AC_FD_CC
438        bnv_qt_lib=qt-mt
439        LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
440        AC_TRY_LINK([#include <$qt_direct_test_header>],
441          $qt_direct_test_main,
442        [
443# Success.
444# We can link with no special library directory.
445          bnv_qt_lib_dir=
446        ], [
447# That did not work. Try the OpenGL version
448          echo "Non-critical error, please neglect the above." >&AC_FD_CC
449          bnv_qt_lib=qt-gl
450          LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
451          AC_TRY_LINK([#include <$qt_direct_test_header>],
452            $qt_direct_test_main,
453          [
454# Success.
455# We can link with no special library directory.
456            bnv_qt_lib_dir=
457          ], [
458# That did not work. Maybe a library version I don't know about?
459            echo "Non-critical error, please neglect the above." >&AC_FD_CC
460# Look for some Qt lib in a standard set of common directories.
461            bnv_dir_list="
462              `echo $bnv_qt_includes | sed ss/includess`
463              /lib
464              /usr/lib64
465              /usr/lib
466              /usr/local/lib64
467              /usr/local/lib
468              /opt/lib64
469              /opt/lib
470              `ls -dr /usr/lib64/qt* 2>/dev/null`
471              `ls -dr /usr/lib64/qt*/lib64 2>/dev/null`
472              `ls -dr /usr/lib/qt* 2>/dev/null`
473              `ls -dr /usr/local/qt* 2>/dev/null`
474              `ls -dr /opt/qt* 2>/dev/null`
475            "
476            for bnv_dir in $bnv_dir_list; do
477              if ls $bnv_dir/libqt* 2>/dev/null; then
478# Gamble that it's the first one...
479                bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p |
480                            sed s@$bnv_dir/lib@@ | sed s/[.].*//`"
481                bnv_qt_lib_dir="$bnv_dir"
482                break
483              fi
484            done
485# Try with that one
486            LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
487            AC_TRY_LINK([#include <$qt_direct_test_header>],
488              $qt_direct_test_main,
489            [
490# Success.
491# We can link with no special library directory.
492              bnv_qt_lib_dir=
493            ], [
494# Leave bnv_qt_lib_dir defined
495            ])
496          ])
497        ])
498      ])
499      if test x"$bnv_qt_lib_dir" != x; then
500        bnv_qt_LIBS="-L$bnv_qt_lib_dir $LIBS"
501      else
502        bnv_qt_LIBS="$LIBS"
503      fi
504      LIBS="$bnv_save_LIBS"
505      CXXFLAGS="$bnv_save_CXXFLAGS"
506    fi dnl $with_Qt_lib_dir was not given
507  fi dnl Done setting up for non-traditional Trolltech installation
508])
509
Note: See TracBrowser for help on using the repository browser.