]> git.lyx.org Git - lyx.git/blob - config/qt.m4
* insetbranch.C (textString): implement, so that branches appear
[lyx.git] / config / qt.m4
1 dnl find a binary in the path
2 AC_DEFUN([QT_FIND_PATH],
3 [
4         AC_MSG_CHECKING([for $1])
5         AC_CACHE_VAL(qt_cv_path_$1,
6         [
7                 qt_cv_path_$1="NONE"
8                 if test -n "$$2"; then
9                         qt_cv_path_$1="$$2";
10                 else
11                         dirs="$3"
12                         qt_save_IFS=$IFS
13                         IFS=':'
14                         for dir in $PATH; do
15                                 dirs="$dirs $dir"
16                         done
17                         IFS=$qt_save_IFS
18
19                         for dir in $dirs; do
20                                 if test -x "$dir/$1"; then
21                                         if test -n "$5"; then
22                                                 evalstr="$dir/$1 $5 2>&1 "
23                                                 if eval $evalstr; then
24                                                         qt_cv_path_$1="$dir/$1"
25                                                         break
26                                                 fi
27                                         else
28                                                 qt_cv_path_$1="$dir/$1"
29                                                 break
30                                         fi
31                                 fi
32                         done
33                 fi
34         ])
35
36         if test -z "$qt_cv_path_$1" || test "$qt_cv_path_$1" = "NONE"; then
37                 AC_MSG_RESULT(not found)
38                 $4
39         else
40                 AC_MSG_RESULT($qt_cv_path_$1)
41                 $2=$qt_cv_path_$1
42         fi
43 ])
44
45 dnl Find the uic compiler on the path or in qt_cv_dir
46 AC_DEFUN([QT_FIND_UIC],
47 [
48         QT_FIND_PATH(uic, ac_uic, $qt_cv_dir/bin)
49         if test -z "$ac_uic" -a "$FATAL" = 1; then
50                 AC_MSG_ERROR([uic binary not found in \$PATH or $qt_cv_dir/bin !])
51         fi
52         AC_MSG_CHECKING([whether uic supports -nounload])
53         if $ac_uic --help 2>&1 | grep nounload >/dev/null ; then
54                 AC_MSG_RESULT([yes])
55                 ac_uic="$ac_uic -nounload"
56         else
57                 AC_MSG_RESULT([no])
58         fi
59 ])
60
61 dnl Find the right moc in path/qt_cv_dir
62 AC_DEFUN([QT_FIND_MOC],
63 [
64         QT_FIND_PATH(moc2, ac_moc2, $qt_cv_dir/bin)
65         QT_FIND_PATH(moc, ac_moc1, $qt_cv_dir/bin)
66
67         if test -n "$ac_moc1" -a -n "$ac_moc2"; then
68                 dnl found both. Prefer Qt3's if it exists else moc2
69                 $ac_moc1 -v 2>&1 | grep "Qt 3" >/dev/null
70                 if test "$?" = 0; then
71                         ac_moc=$ac_moc1;
72                 else
73                         ac_moc=$ac_moc2;
74                 fi
75         else
76                 if test -n "$ac_moc1"; then
77                         ac_moc=$ac_moc1;
78                 else
79                         ac_moc=$ac_moc2;
80                 fi
81         fi
82
83         if test -z "$ac_moc"  -a "$FATAL" = 1; then
84                 AC_MSG_ERROR([moc binary not found in \$PATH or $qt_cv_dir/bin !])
85         fi
86 ])
87
88 dnl check a particular libname
89 AC_DEFUN([QT_TRY_LINK],
90 [
91         SAVE_LIBS="$LIBS"
92         LIBS="$LIBS $1"
93         AC_TRY_LINK([
94         #include <qglobal.h>
95         #include <qstring.h>
96                 ],
97         [
98         QString s("mangle_failure");
99         #if (QT_VERSION < 0x030000)
100         break_me_(\\\);
101         #endif
102         ],
103         qt_cv_libname=$1,
104         )
105         LIBS="$SAVE_LIBS"
106 ])
107
108 dnl check we can do a compile
109 AC_DEFUN([QT_CHECK_COMPILE],
110 [
111         AC_MSG_CHECKING([for Qt library name])
112
113         AC_CACHE_VAL(qt_cv_libname,
114         [
115                 AC_LANG_CPLUSPLUS
116                 SAVE_CXXFLAGS=$CXXFLAGS
117                 CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS"
118
119                 for libname in -lqt-mt -lqt;
120                 do
121                         QT_TRY_LINK($libname)
122                         if test -n "$qt_cv_libname"; then
123                                 break;
124                         fi
125                 done
126
127                 CXXFLAGS=$SAVE_CXXFLAGS
128         ])
129
130         if test -z "$qt_cv_libname"; then
131                 AC_MSG_RESULT([failed])
132                 if test "$FATAL" = 1 ; then
133                         AC_MSG_ERROR([Cannot compile a simple Qt executable. Check you have the right \$QTDIR !])
134                 fi
135         else
136                 AC_MSG_RESULT([$qt_cv_libname])
137         fi
138 ])
139
140 dnl get Qt version we're using
141 AC_DEFUN([QT_GET_VERSION],
142 [
143         AC_CACHE_CHECK([Qt version],lyx_cv_qtversion,
144         [
145                 AC_LANG_CPLUSPLUS
146                 SAVE_CPPFLAGS=$CPPFLAGS
147                 CPPFLAGS="$CPPFLAGS $QT_INCLUDES"
148
149                 cat > conftest.$ac_ext <<EOF
150 #line __oline__ "configure"
151 #include "confdefs.h"
152 #include <qglobal.h>
153 "%%%"QT_VERSION_STR"%%%"
154 EOF
155                 lyx_cv_qtversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
156                         grep '^"%%%"'  2>/dev/null | \
157                         sed -e 's/"%%%"//g' -e 's/"//g'`
158                 rm -f conftest.$ac_ext
159                 CPPFLAGS=$SAVE_CPPFLAGS
160         ])
161
162         QT_VERSION=$lyx_cv_qtversion
163         AC_SUBST(QT_VERSION)
164 ])
165
166 dnl Ascertain whether the Qt libraries are multi-threaded or not
167 AC_DEFUN([QT_CHECK_IS_MULTITHREADED],
168 [
169         AC_CACHE_CHECK([whether the Qt library is multi-threaded],
170                        qt_cv_is_multithreaded,
171         [
172                 AC_LANG_CPLUSPLUS
173                 SAVE_CXXFLAGS=$CXXFLAGS
174                 SAVE_LIBS="$LIBS"
175                 CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS"
176                 LIBS="$LIBS $QT_LIB"
177
178                 AC_TRY_LINK(
179                 [
180 #define QT_THREAD_SUPPORT
181 #include <qapplication.h>
182                 ],
183                 [
184         QApplication a(0,0);
185         a.unlock();
186                 ],
187                 qt_cv_is_multithreaded=yes,
188                 qt_cv_is_multithreaded=no
189                 )
190
191                 LIBS="$SAVE_LIBS"
192                 CXXFLAGS=$SAVE_CXXFLAGS
193         ])
194
195         if test x"$qt_cv_is_multithreaded" = xyes; then
196                 QT_CPPFLAGS="$QT_CPPFLAGS -DQT_THREAD_SUPPORT"
197         fi
198 ])
199
200 dnl start here
201 AC_DEFUN([QT_DO_IT_ALL],
202 [
203         dnl this variable is precious
204         AC_ARG_VAR(QTDIR, [the place where the Qt files are, e.g. /usr/lib/qt])
205
206         dnl Please leave this alone. I use this file in
207         dnl oprofile.
208         FATAL=0
209
210         AC_ARG_WITH(qt-dir, [  --with-qt-dir           where the root of Qt is installed ],
211                 [ qt_cv_dir=`eval echo "$withval"/` ])
212
213         AC_ARG_WITH(qt-includes, [  --with-qt-includes      where the Qt includes are. ],
214                 [ qt_cv_includes=`eval echo "$withval"` ])
215
216         AC_ARG_WITH(qt-libraries, [  --with-qt-libraries     where the Qt library is installed.],
217                 [  qt_cv_libraries=`eval echo "$withval"` ])
218
219         dnl pay attention to $QTDIR unless overridden
220         if test -z "$qt_cv_dir"; then
221                 qt_cv_dir=$QTDIR
222         fi
223
224         dnl derive inc/lib if needed
225         if test -n "$qt_cv_dir"; then
226                 if test -z "$qt_cv_includes"; then
227                         qt_cv_includes=$qt_cv_dir/include
228                 fi
229                 if test -z "$qt_cv_libraries"; then
230                         qt_cv_libraries=$qt_cv_dir/lib
231                 fi
232         fi
233
234         dnl flags for compilation
235         QT_INCLUDES=
236         QT_LDFLAGS=
237         if test -n "$qt_cv_includes"; then
238                 QT_INCLUDES="-I$qt_cv_includes"
239         fi
240         if test -n "$qt_cv_libraries"; then
241                 QT_LDFLAGS="-L$qt_cv_libraries"
242         fi
243         AC_SUBST(QT_INCLUDES)
244         AC_SUBST(QT_LDFLAGS)
245
246         dnl Preprocessor flags
247         QT_CPPFLAGS="-DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_STL -DQT_NO_EMIT"
248         case ${host} in
249         *mingw*) QT_CPPFLAGS="-DQT_DLL $QT_CPPFLAGS";;
250         esac
251
252         case ${host_os} in
253         cygwin* ) 
254                 if test "x$with_x" = xno ; then 
255                         QT_CPPFLAGS="$QT_CPPFLAGS -DQ_CYGWIN_WIN"
256                 fi;;
257         esac
258
259         AC_SUBST(QT_CPPFLAGS)
260
261         if test -z "$MOC"; then
262                 QT_FIND_MOC
263                 MOC=$ac_moc
264         fi
265         AC_SUBST(MOC)
266         if test -z "$UIC"; then
267                 QT_FIND_UIC
268                 UIC=$ac_uic
269         fi
270         AC_SUBST(UIC)
271
272         QT_CHECK_COMPILE
273
274         QT_LIB=$qt_cv_libname;
275         AC_SUBST(QT_LIB)
276
277         QT_CHECK_IS_MULTITHREADED
278
279         if test -n "$qt_cv_libname"; then
280                 QT_GET_VERSION
281         fi
282 ])