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