]> git.lyx.org Git - lyx.git/blob - config/qt2.m4
more work on \parbox support
[lyx.git] / config / qt2.m4
1 # Configure paths and libs when using Qt GUI
2 ##    -*- shell-script -*-
3
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)
7
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.
12
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.
17
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.       
22
23 AC_DEFUN(QT2_MOC_ERROR_MESSAGE,
24 [
25     AC_MSG_ERROR([No Qt meta object compiler (moc) found!
26 Please check whether you installed Qt correctly.
27 You need to have a running moc binary.
28 configure tried to run $ac_cv_path_qt2moc and the test didn't
29 succeed. If configure shouldn't have tried this one, set
30 the environment variable MOC to the right one before running
31 configure.
32 ])
33 ])
34
35 AC_DEFUN(QT2_FIND_PATH,
36 [
37    AC_MSG_CHECKING([for $1])
38    AC_CACHE_VAL(qt2_cv_path_$1,
39    [
40      qt2_cv_path_$1="NONE"
41      if test -n "$$2"; then
42         qt2_cv_path_$1="$$2";
43      else
44         dirs="$3"
45         qt2_save_IFS=$IFS
46         IFS=':'
47         for dir in $PATH; do
48           dirs="$dirs $dir"
49         done
50         IFS=$qt2_save_IFS
51  
52         for dir in $dirs; do
53           if test -x "$dir/$1"; then
54             if test -n "$5"
55             then
56               evalstr="$dir/$1 $5 2>&1 "
57               if eval $evalstr; then
58                 qt2_cv_path_$1="$dir/$1"
59                 break
60               fi
61             else
62                 qt2_cv_path_$1="$dir/$1"
63                 break
64             fi
65           fi
66         done
67  
68      fi
69  
70    ])
71  
72    if test -z "$qt2_cv_path_$1" || test "$qt2_cv_path_$1" = "NONE"; then
73       AC_MSG_RESULT(not found)
74       $4
75    else
76      AC_MSG_RESULT($qt2_cv_path_$1)
77      $2=$qt2_cv_path_$1
78    fi
79 ])
80  
81 dnl ------------------------------------------------------------------------
82 dnl Find the UIC compiler if available
83 dnl ------------------------------------------------------------------------
84 AC_DEFUN(QT2_AC_PATH_UIC,
85 [
86    QT2_FIND_PATH(uic, UIC, [$ac_qt2_bindir $QTDIR/bin \
87             /usr/bin /usr/X11R6/bin /usr/lib/qt2/bin \
88             /usr/local/qt2/bin /usr/local/qt/bin /usr/lib/qt/bin], )
89    AC_SUBST(UIC)
90 ])
91  
92 dnl ------------------------------------------------------------------------
93 dnl Find the meta object compiler in the PATH, in $QTDIR/bin, and some
94 dnl more usual places
95 dnl ------------------------------------------------------------------------
96 dnl
97 AC_DEFUN(QT2_AC_PATH_MOC,
98 [
99    QT2_FIND_PATH(moc, MOC, [$ac_qt2_bindir $QTDIR/bin \
100             /usr/bin /usr/X11R6/bin /usr/lib/qt2/bin \
101             /usr/local/qt2/bin /usr/local/qt/bin /usr/lib/qt/bin],)
102
103    QT2_FIND_PATH(moc2, MOC2, [$ac_qt2_bindir $QTDIR/bin \
104             /usr/bin /usr/X11R6/bin /usr/lib/qt2/bin \
105             /usr/local/qt2/bin /usr/local/qt/bin /usr/lib/qt/bin],)
106  
107    if ! test -z "$MOC2"; then
108      MOC="$MOC2";
109    fi 
110  
111    if test -z "$MOC"; then
112      if test -n "$ac_cv_path_qt2moc"; then
113        output=`eval "$ac_cv_path_qt2moc --help 2>&1 | sed -e '1q' | grep Qt"`
114      fi
115      echo "configure:__oline__: tried to call $ac_cv_path_qt2moc --help 2>&1 | sed -e '1q' | grep Qt" >&AC_FD_CC
116      echo "configure:__oline__: moc output: $output" >&AC_FD_CC
117
118      if test -z "$output"; then
119        QT2_MOC_ERROR_MESSAGE
120     fi
121    fi
122
123    AC_SUBST(MOC)
124 ])
125
126 AC_DEFUN(QT2_PRINT_PROGRAM,
127 [
128 AC_LANG_CPLUSPLUS
129 cat > conftest.$ac_ext <<EOF
130 #include "confdefs.h"
131 #include <qmovie.h>
132 #include <qapplication.h>
133 int main() {
134   QMovie m;
135   m.setSpeed(20);
136   return 0;
137 }
138 EOF
139 ])
140
141 dnl check for -lqt2 not -lqt
142 AC_DEFUN(QT2_CHECK_LIB_NAME,
143 [
144 ac_cxxflags_safe="$CXXFLAGS"
145 ac_ldflags_safe="$LDFLAGS"
146 ac_libs_safe="$LIBS"
147
148 CXXFLAGS="$CXXFLAGS -I$qt2_incdir"
149 LDFLAGS="-L$qt2_libdir $X_LDFLAGS"
150 LIBS="$LIBS -lqt2 -lXext -lX11 $LIBSOCKET"
151
152 QT2_PRINT_PROGRAM
153
154 if AC_TRY_EVAL(ac_link) && test -s conftest; then
155   rm -f conftest*
156   ac_qt2_name="-lqt2"
157 else
158   echo "configure: failed program was:" >&AC_FD_CC
159   cat conftest.$ac_ext >&AC_FD_CC
160 fi
161 rm -f conftest*
162 CXXFLAGS="$ac_cxxflags_safe"
163 LDFLAGS="$ac_ldflags_safe"
164 LIBS="$ac_libs_safe"
165 ])
166
167 ## ------------------------------------------------------------------------
168 ## Try to find the Qt2 headers and libraries.
169 ## $(QT2_LDFLAGS) will be -Lqt2liblocation (if needed)
170 ## and $(QT2_INCLUDES) will be -Iqt2hdrlocation (if needed)
171 ## ------------------------------------------------------------------------
172 ##
173 AC_DEFUN(QT2_AC_PATH,
174 [
175 AC_MSG_CHECKING([for Qt])
176 ac_qt2_includes=NO ac_qt2_libraries=NO ac_qt2_bindir=NO
177 qt2_libraries=""
178 qt2_includes=""
179  
180 AC_ARG_WITH(qt-dir,
181     [  --with-qt-dir           where the root of Qt 2/3 is installed ],
182     [  ac_qt2_includes=`eval echo "$withval"/include`
183        ac_qt2_libraries=`eval echo "$withval"/lib`
184        ac_qt2_bindir=`eval echo "$withval"/bin`
185     ])
186
187 AC_ARG_WITH(qt-includes,
188     [  --with-qt-includes      where the Qt 2/3 includes are. ],
189     [ 
190        ac_qt2_includes=`eval echo "$withval"`
191     ])
192    
193 qt2_libs_given=no
194
195 AC_ARG_WITH(qt-libraries,
196     [  --with-qt-libraries     where the Qt 2/3 library is installed.],
197     [  ac_qt2_libraries=`eval echo "$withval"`
198        qt2_libs_given=yes
199     ])
200
201 if test "$ac_qt2_includes" = NO || test "$ac_qt2_libraries" = NO; then
202
203 AC_CACHE_VAL(ac_cv_have_qt2,
204 [#try to guess Qt2 locations
205
206 qt2_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"
207 test -n "$QTDIR" && qt2_incdirs="$QTDIR/include/qt2 $QTDIR/include/qt $QTDIR/include $QTDIR $qt2_incdirs"
208 AC_FIND_FILE(qmovie.h, $qt2_incdirs, qt2_incdir)
209 ac_qt2_includes="$qt2_incdir"
210
211 if test ! "$ac_qt2_libraries" = "NO"; then
212   qt2_libdirs="$ac_qt2_libraries"
213 fi
214
215 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"
216 test -n "$QTDIR" && qt2_libdirs="$QTDIR/lib $QTDIR $qt2_libdirs"
217
218 test=NONE
219 qt2_libdir=NONE
220 for dir in $qt2_libdirs; do
221   try="ls -1 $dir/libqt*"
222   if test=`eval $try 2> /dev/null`; then qt2_libdir=$dir; break; else echo "tried $dir" >&AC_FD_CC ; fi
223 done
224
225 ac_qt2_name="-lqt"
226  
227 AC_FIND_FILE(libqt.so.3 libqt.so.2.2.3 libqt.so.2.2 libqt.so.2 libqt2.so libqt.a libqt.sl, $qt2_libdirs, qt2_libdir)
228  
229 ac_qt2_libraries="$qt2_libdir"
230
231 QT2_CHECK_LIB_NAME
232
233 if test "$ac_qt2_name" = "-lqt"; then
234   ac_qt2_libraries="$qt2_libdir"
235
236   ac_cxxflags_safe="$CXXFLAGS"
237   ac_ldflags_safe="$LDFLAGS"
238   ac_libs_safe="$LIBS"
239
240   CXXFLAGS="$CXXFLAGS -I$qt2_incdir"
241   LDFLAGS="-L$qt2_libdir $X_LDFLAGS"
242   LIBS="$LIBS -lqt -lXext -lX11 $LIBSOCKET"
243
244   QT2_PRINT_PROGRAM
245
246   if AC_TRY_EVAL(ac_link) && test -s conftest; then
247     rm -f conftest*
248   else
249       echo "configure: failed program was:" >&AC_FD_CC
250       cat conftest.$ac_ext >&AC_FD_CC
251       ac_qt2_libraries="NO"
252   fi
253   rm -f conftest*
254   CXXFLAGS="$ac_cxxflags_safe"
255   LDFLAGS="$ac_ldflags_safe"
256   LIBS="$ac_libs_safe"
257 fi
258
259 if test "$ac_qt2_includes" = NO || test "$ac_qt2_libraries" = NO; then
260   ac_cv_have_qt2="have_qt2=no"
261   ac_qt2_notfound=""
262   if test "$ac_qt2_includes" = NO; then
263     if test "$ac_qt2_libraries" = NO; then
264       ac_qt2_notfound="(headers and libraries)";
265     else
266       ac_qt2_notfound="(headers)";
267     fi
268   else
269     ac_qt2_notfound="(libraries)";
270   fi
271
272   AC_MSG_ERROR([Qt2 $ac_qt2_notfound not found. Please check your installation! ]);
273 else
274   have_qt2="yes"
275 fi
276 ])
277 else
278   dnl libs and headers supplied. Need to check lib name
279   qt2_incdir="$ac_qt2_includes"
280   qt2_libdir="$ac_qt2_libraries" 
281   ac_qt2_name="-lqt"
282   QT2_CHECK_LIB_NAME
283   have_qt2="yes"
284 fi
285
286 eval "$ac_cv_have_qt2"
287
288 if test "$have_qt2" != yes; then
289   AC_MSG_RESULT([$have_qt2]);
290 else
291   ac_cv_have_qt2="have_qt2=yes ac_qt2_name=$ac_qt2_name \
292     ac_qt2_includes=$ac_qt2_includes ac_qt2_libraries=$ac_qt2_libraries"
293   AC_MSG_RESULT([libraries $ac_qt2_name in $ac_qt2_libraries, headers $ac_qt2_includes])
294  
295   qt2_libraries="$ac_qt2_libraries"
296   qt2_includes="$ac_qt2_includes"
297 fi
298
299 dnl check it is Qt2
300
301 SAVE_CXXFLAGS="$CXXFLAGS"
302 CXXFLAGS="$CXXFLAGS -I$qt2_includes -L$qt2_libraries"
303 dnl specify we are definitely C++ compiling first
304 AC_LANG_CPLUSPLUS
305 AC_TRY_COMPILE([
306 #include <qglobal.h>
307 ],
308 [
309 #if (QT_VERSION < 221)
310 break_me_(\\\);
311 #endif
312 ],
313 ac_qt2_ok=yes,
314 ac_qt2_ok=no
315 )
316 test "$ac_qt2_ok" = no && AC_MSG_ERROR([Found an earlier version of Qt - you must specify the path to Qt2])
317 CXXFLAGS="$SAVE_CXXFLAGS"
318
319 AC_SUBST(qt2_libraries)
320 AC_SUBST(qt2_includes)
321
322 if test "$qt2_includes" = "$x_includes" || test -z "$qt2_includes"; then
323  QT2_INCLUDES="";
324 else
325  QT2_INCLUDES="-I$qt2_includes"
326  all_includes="$QT2_INCLUDES $all_includes"
327 fi
328
329 if test "$qt2_libraries" = "$x_libraries" || test -z "$qt2_libraries"; then
330  QT2_LDFLAGS=""
331 else
332  QT2_LDFLAGS="-L$qt2_libraries"
333  all_libraries="$QT2_LDFLAGS $all_libraries"
334 fi
335
336 QT2_LIBS="$ac_qt2_name"
337  
338 AC_SUBST(QT2_INCLUDES)
339 AC_SUBST(QT2_LDFLAGS)
340 AC_SUBST(QT2_LIBS)
341 QT2_AC_PATH_MOC
342 QT2_AC_PATH_UIC
343 ])
344
345 AC_DEFUN(QT2_DO_IT_ALL,
346 [
347 if test "$QT2DIR" != ""; then
348         QTDIR=$QT2DIR
349 fi
350 QT2_AC_PATH
351 ])