This commit was manufactured by cvs2svn to create tag
[lyx.git] / config / qt2.m4
blobd973e9dca92d74cf5ed4f2a74a42c0e79e3651e5
1 # Configure paths and libs when using Qt2 GUI
2 ##    -*- shell-script -*-
4 ##    Based on KDE file written by :
5 ##    Copyright (C) 1997 Janos Farkas (chexum@shadow.banki.hu)
6 ##              (C) 1997 Stephan Kulow (coolo@kde.org)
8 ##    This file is free software; you can redistribute it and/or
9 ##    modify it under the terms of the GNU Library General Public
10 ##    License as published by the Free Software Foundation; either
11 ##    version 2 of the License, or (at your option) any later version.
13 ##    This library is distributed in the hope that it will be useful,
14 ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 ##    Library General Public License for more details.
18 ##    You should have received a copy of the GNU Library General Public License
19 ##    along with this library; see the file COPYING.LIB.  If not, write to
20 ##    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ##    Boston, MA 02111-1307, USA.       
23 ## ------------------------------------------------------------------------
24 ## Find a file (or one of more files in a list of dirs)
25 ## ------------------------------------------------------------------------
28 AC_DEFUN(QT2_MOC_ERROR_MESSAGE,
30     AC_MSG_ERROR([No Qt meta object compiler (moc) found!
31 Please check whether you installed Qt correctly.
32 You need to have a running moc binary.
33 configure tried to run $ac_cv_path_qt2moc and the test didn't
34 succeed. If configure shouldn't have tried this one, set
35 the environment variable MOC to the right one before running
36 configure.
40 AC_DEFUN(QT2_FIND_PATH,
42    AC_MSG_CHECKING([for $1])
43    AC_CACHE_VAL(qt2_cv_path_$1,
44    [
45      qt2_cv_path_$1="NONE"
46      if test -n "$$2"; then
47         qt2_cv_path_$1="$$2";
48      else
49         dirs="$3"
50         qt2_save_IFS=$IFS
51         IFS=':'
52         for dir in $PATH; do
53           dirs="$dirs $dir"
54         done
55         IFS=$qt2_save_IFS
57         for dir in $dirs; do
58           if test -x "$dir/$1"; then
59             if test -n "$5"
60             then
61               evalstr="$dir/$1 $5 2>&1 "
62               if eval $evalstr; then
63                 qt2_cv_path_$1="$dir/$1"
64                 break
65               fi
66             else
67                 qt2_cv_path_$1="$dir/$1"
68                 break
69             fi
70           fi
71         done
73      fi
75    ])
77    if test -z "$qt2_cv_path_$1" || test "$qt2_cv_path_$1" = "NONE"; then
78       AC_MSG_RESULT(not found)
79       $4
80    else
81      AC_MSG_RESULT($qt2_cv_path_$1)
82      $2=$qt2_cv_path_$1
83    fi
86 dnl ------------------------------------------------------------------------
87 dnl Find the UIC compiler if available
88 dnl ------------------------------------------------------------------------
89 AC_DEFUN(QT2_AC_PATH_UIC,
91    QT2_FIND_PATH(uic, UIC, [$ac_qt2_bindir $QTDIR/bin \
92             /usr/bin /usr/X11R6/bin /usr/lib/qt2/bin \
93             /usr/local/qt2/bin /usr/local/qt/bin /usr/lib/qt/bin], )
94    AC_SUBST(UIC)
97 dnl ------------------------------------------------------------------------
98 dnl Find the meta object compiler in the PATH, in $QTDIR/bin, and some
99 dnl more usual places
100 dnl ------------------------------------------------------------------------
102 AC_DEFUN(QT2_AC_PATH_MOC,
104    QT2_FIND_PATH(moc, MOC, [$ac_qt2_bindir $QTDIR/bin \
105             /usr/bin /usr/X11R6/bin /usr/lib/qt2/bin \
106             /usr/local/qt2/bin /usr/local/qt/bin /usr/lib/qt/bin], [QT2_MOC_ERROR_MESSAGE])
108    if test -z "$MOC"; then
109      if test -n "$ac_cv_path_qt2moc"; then
110        output=`eval "$ac_cv_path_qt2moc --help 2>&1 | sed -e '1q' | grep Qt"`
111      fi
112      echo "configure:__oline__: tried to call $ac_cv_path_qt2moc --help 2>&1 | sed -e '1q' | grep Qt" >&AC_FD_CC
113      echo "configure:__oline__: moc output: $output" >&AC_FD_CC
115      if test -z "$output"; then
116        MOC_ERROR_MESSAGE
117     fi
118    fi
120    AC_SUBST(MOC)
123 AC_DEFUN(QT2_PRINT_PROGRAM,
125 AC_LANG_CPLUSPLUS
126 cat > conftest.$ac_ext <<EOF
127 #include "confdefs.h"
128 #include <qmovie.h>
129 #include <qapplication.h>
130 int main() {
131   QMovie m;
132   m.setSpeed(20);
133   return 0;
138 AC_DEFUN(QT2_CHECK_DIRECT,
140 AC_MSG_CHECKING([if Qt2 compiles without flags])
141 AC_CACHE_VAL(cv_qt2_direct,
143 ac_LD_LIBRARY_PATH_safe=$LD_LIBRARY_PATH
144 ac_LIBRARY_PATH="$LIBRARY_PATH"
145 ac_cxxflags_safe="$CXXFLAGS"
146 ac_ldflags_safe="$LDFLAGS"
147 ac_libs_safe="$LIBS"
149 CXXFLAGS="$CXXFLAGS -I$qt2_includes"
150 LDFLAGS="$X_LDFLAGS"
151 LIBS="-lqt -lXext -lX11 $LIBSOCKET"
152 LD_LIBRARY_PATH=
153 export LD_LIBRARY_PATH
154 LIBRARY_PATH=
155 export LIBRARY_PATH
157 QT2_PRINT_PROGRAM
159 if AC_TRY_EVAL(ac_link) && test -s conftest; then
160   cv_qt2_direct="yes"
161 else
162   cv_qt2_direct="no"
163   echo "configure: failed program was:" >&AC_FD_CC
164   cat conftest.$ac_ext >&AC_FD_CC
166 rm -f conftest*
167 CXXFLAGS="$ac_cxxflags_safe"
168 LDFLAGS="$ac_ldflags_safe"
169 LIBS="$ac_libs_safe"
171 LD_LIBRARY_PATH="$ac_LD_LIBRARY_PATH_safe"
172 export LD_LIBRARY_PATH
173 LIBRARY_PATH="$ac_LIBRARY_PATH"
174 export LIBRARY_PATH
177 if test "$cv_qt2_direct" = "yes"; then
178   AC_MSG_RESULT(yes)
179   $1
180 else
181   AC_MSG_RESULT(no)
182   $2
186 ## ------------------------------------------------------------------------
187 ## Try to find the Qt2 headers and libraries.
188 ## $(QT2_LDFLAGS) will be -Lqt2liblocation (if needed)
189 ## and $(QT2_INCLUDES) will be -Iqt2hdrlocation (if needed)
190 ## ------------------------------------------------------------------------
192 AC_DEFUN(QT2_AC_PATH,
194 AC_MSG_CHECKING([for Qt 2])
195 ac_qt2_includes=NO ac_qt2_libraries=NO ac_qt2_bindir=NO
196 qt2_libraries=""
197 qt2_includes=""
199 AC_ARG_WITH(qt2-dir,
200     [  --with-qt2-dir           where the root of Qt2 is installed ],
201     [  ac_qt2_includes="$withval"/include
202        ac_qt2_libraries="$withval"/lib
203        ac_qt2_bindir="$withval"/bin
204     ])
206 AC_ARG_WITH(qt2-includes,
207     [  --with-qt2-includes      where the Qt2 includes are. ],
208     [ 
209        ac_qt2_includes="$withval"
210     ])
211    
212 qt2_libs_given=no
214 AC_ARG_WITH(qt2-libraries,
215     [  --with-qt2-libraries     where the Qt2 library is installed.],
216     [  ac_qt2_libraries="$withval"
217        qt2_libs_given=yes
218     ])
220 if test "$ac_qt2_includes" = NO || test "$ac_qt2_libraries" = NO; then
222 AC_CACHE_VAL(ac_cv_have_qt2,
223 [#try to guess Qt2 locations
225 qt_incdirs="$ac_qt2_includes usr/lib/qt2/include /usr/local/qt2/include /usr/include/qt2 /usr/X11R6/include/X11/qt2 /usr/lib/qt/include /usr/local/qt/include /usr/include/qt /usr/include /usr/X11R6/include/X11/qt $x_includes $QTINC"
226 test -n "$QTDIR" && qt2_incdirs="$QTDIR/include/qt2 $QTDIR/include/qt $QTDIR/include $QTDIR $qt2_incdirs"
227 AC_FIND_FILE(qmovie.h, $qt2_incdirs, qt2_incdir)
228 ac_qt2_includes="$qt2_incdir"
230 if test ! "$ac_qt2_libraries" = "NO"; then
231   qt2_libdirs="$ac_qt2_libraries"
234 qt2_libdirs="$qt2_libdirs /usr/lib/qt2/lib /usr/lib/qt/lib /usr/X11R6/lib /usr/lib /usr/local/qt2/lib /usr/lib/qt2 /usr/local/qt/lib /usr/lib/qt $x_libraries $QTLIB"
235 test -n "$QTDIR" && qt2_libdirs="$QTDIR/lib $QTDIR $qt2_libdirs"
237 test=NONE
238 qt2_libdir=NONE
239 for dir in $qt2_libdirs; do
240   try="ls -1 $dir/libqt*"
241   if test=`eval $try 2> /dev/null`; then qt2_libdir=$dir; break; else echo "tried $dir" >&AC_FD_CC ; fi
242 done
244 dnl AC_FIND_FILE(libqt.so.2.2.3 libqt.so.2.2 libqt.so.2 libqt2.so libqt.a libqt.sl, $qt2_libdirs, qt2_libdir)
245 ac_qt2_libraries="$qt2_libdir"
247 ac_cxxflags_safe="$CXXFLAGS"
248 ac_ldflags_safe="$LDFLAGS"
249 ac_libs_safe="$LIBS"
251 CXXFLAGS="$CXXFLAGS -I$qt2_incdir"
252 LDFLAGS="-L$qt2_libdir $X_LDFLAGS"
253 LIBS="$LIBS -lqt -lXext -lX11 $LIBSOCKET"
255 QT2_PRINT_PROGRAM
257 if AC_TRY_EVAL(ac_link) && test -s conftest; then
258   rm -f conftest*
259 else
260   echo "configure: failed program was:" >&AC_FD_CC
261   cat conftest.$ac_ext >&AC_FD_CC
262   ac_qt2_libraries="NO"
264 rm -f conftest*
265 CXXFLAGS="$ac_cxxflags_safe"
266 LDFLAGS="$ac_ldflags_safe"
267 LIBS="$ac_libs_safe"
269 if test "$ac_qt2_includes" = NO || test "$ac_qt2_libraries" = NO; then
270   ac_cv_have_qt2="have_qt2=no"
271   ac_qt2_notfound=""
272   if test "$ac_qt2_includes" = NO; then
273     if test "$ac_qt2_libraries" = NO; then
274       ac_qt2_notfound="(headers and libraries)";
275     else
276       ac_qt2_notfound="(headers)";
277     fi
278   else
279     ac_qt2_notfound="(libraries)";
280   fi
282   AC_MSG_ERROR([Qt2 $ac_qt2_notfound not found. Please check your installation! ]);
283 else
284   have_qt2="yes"
287 else
288   have_qt2="yes"
291 eval "$ac_cv_have_qt2"
293 if test "$have_qt2" != yes; then
294   AC_MSG_RESULT([$have_qt2]);
295 else
296   ac_cv_have_qt2="have_qt2=yes \
297     ac_qt2_includes=$ac_qt2_includes ac_qt2_libraries=$ac_qt2_libraries"
298   AC_MSG_RESULT([libraries $ac_qt2_libraries, headers $ac_qt2_includes])
300   qt2_libraries="$ac_qt2_libraries"
301   qt2_includes="$ac_qt2_includes"
304 if test ! "$qt2_libs_given" = "yes"; then
305 QT2_CHECK_DIRECT(qt2_libraries= ,[])
308 dnl check it is Qt2
310 SAVE_CXXFLAGS="$CXXFLAGS"
311 CXXFLAGS="$CXXFLAGS -I$qt2_includes -L$qt2_libraries"
312 dnl specify we are definitely C++ compiling first
313 AC_LANG_CPLUSPLUS
314 AC_TRY_COMPILE([
315 #include <qglobal.h>
318 #if (QT_VERSION < 223)
319 break_me_(\\\);
320 #endif
322 ac_qt2_ok=yes,
323 ac_qt2_ok=no
325 test "$ac_qt2_ok" = no && AC_MSG_ERROR([Found an earlier version of Qt - you must specify the path to Qt2])
326 CXXFLAGS="$SAVE_CXXFLAGS"
328 AC_SUBST(qt2_libraries)
329 AC_SUBST(qt2_includes)
331 if test "$qt2_includes" = "$x_includes" || test -z "$qt2_includes"; then
332  QT2_INCLUDES="";
333 else
334  QT2_INCLUDES="-I$qt2_includes"
335  all_includes="$QT2_INCLUDES $all_includes"
338 if test "$qt2_libraries" = "$x_libraries" || test -z "$qt2_libraries"; then
339  QT2_LDFLAGS=""
340 else
341  QT2_LDFLAGS="-L$qt2_libraries"
342  all_libraries="$QT2_LDFLAGS $all_libraries"
345 QT2_LIBS="-lqt"
347 AC_SUBST(QT2_INCLUDES)
348 AC_SUBST(QT2_LDFLAGS)
349 AC_SUBST(QT2_LIBS)
350 QT2_AC_PATH_MOC
351 QT2_AC_PATH_UIC
354 AC_DEFUN(QT2_DO_IT_ALL,
356 if test "$QT2DIR" != ""; then
357         QTDIR=$QT2DIR
359 QT2_AC_PATH