blob: b0e30ef0ec152694ea379fc2c46009eb0f1bfa57 [file] [log] [blame]
Mike Dodd8cfa7022010-11-17 11:12:26 -08001dnl find a binary in the path
2AC_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
45dnl Find the uic compiler on the path or in qt_cv_dir
46AC_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])
53
54dnl Find the right moc in path/qt_cv_dir
55AC_DEFUN([QT_FIND_MOC],
56[
57 QT_FIND_PATH(moc2, ac_moc2, $qt_cv_dir/bin)
58 QT_FIND_PATH(moc, ac_moc1, $qt_cv_dir/bin)
59
60 if test -n "$ac_moc1" -a -n "$ac_moc2"; then
61 dnl found both. Prefer Qt3's if it exists else moc2
62 $ac_moc1 -v 2>&1 | grep "Qt 3" >/dev/null
63 if test "$?" = 0; then
64 ac_moc=$ac_moc1;
65 else
66 ac_moc=$ac_moc2;
67 fi
68 else
69 if test -n "$ac_moc1"; then
70 ac_moc=$ac_moc1;
71 else
72 ac_moc=$ac_moc2;
73 fi
74 fi
75
76 if test -z "$ac_moc" -a "$FATAL" = 1; then
77 AC_MSG_ERROR([moc binary not found in \$PATH or $qt_cv_dir/bin !])
78 fi
79])
80
81dnl check a particular libname
82AC_DEFUN([QT_TRY_LINK],
83[
84 SAVE_LIBS="$LIBS"
85 LIBS="$LIBS $1"
86 AC_TRY_LINK([
87 #include <qglobal.h>
88 #include <qstring.h>
89 ],
90 [
91 QString s("mangle_failure");
92 #if (QT_VERSION < 221)
93 break_me_(\\\);
94 #endif
95 ],
96 qt_cv_libname=$1,
97 )
98 LIBS="$SAVE_LIBS"
99])
100
101dnl check we can do a compile
102AC_DEFUN([QT_CHECK_COMPILE],
103[
104 AC_MSG_CHECKING([for Qt library name])
105
106 AC_CACHE_VAL(qt_cv_libname,
107 [
108 AC_LANG_CPLUSPLUS
109 SAVE_CXXFLAGS=$CXXFLAGS
110 CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS"
111
112 for libname in -lqt-mt -lqt3 -lqt2 -lqt;
113 do
114 QT_TRY_LINK($libname)
115 if test -n "$qt_cv_libname"; then
116 break;
117 fi
118 done
119
120 CXXFLAGS=$SAVE_CXXFLAGS
121 ])
122
123 if test -z "$qt_cv_libname"; then
124 AC_MSG_RESULT([failed])
125 if test "$FATAL" = 1 ; then
126 AC_MSG_ERROR([Cannot compile a simple Qt executable. Check you have the right \$QTDIR !])
127 fi
128 else
129 AC_MSG_RESULT([$qt_cv_libname])
130 fi
131])
132
133dnl get Qt version we're using
134AC_DEFUN([QT_GET_VERSION],
135[
136 AC_CACHE_CHECK([Qt version],lyx_cv_qtversion,
137 [
138 AC_LANG_CPLUSPLUS
139 SAVE_CPPFLAGS=$CPPFLAGS
140 CPPFLAGS="$CPPFLAGS $QT_INCLUDES"
141
142 cat > conftest.$ac_ext <<EOF
143#line __oline__ "configure"
144#include "confdefs.h"
145#include <qglobal.h>
146"%%%"QT_VERSION_STR"%%%"
147EOF
148 lyx_cv_qtversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
149 grep '^"%%%"' 2>/dev/null | \
150 sed -e 's/"%%%"//g' -e 's/"//g'`
151 rm -f conftest.$ac_ext
152 CPPFLAGS=$SAVE_CPPFLAGS
153 ])
154
155 QT_VERSION=$lyx_cv_qtversion
156 AC_SUBST(QT_VERSION)
157])
158
159dnl start here
160AC_DEFUN([QT_DO_IT_ALL],
161[
162 dnl Please leave this alone. I use this file in
163 dnl oprofile.
164 FATAL=0
165
166 AC_ARG_WITH(qt-dir, [ --with-qt-dir where the root of Qt is installed ],
167 [ qt_cv_dir=`eval echo "$withval"/` ])
168
169 AC_ARG_WITH(qt-includes, [ --with-qt-includes where the Qt includes are. ],
170 [ qt_cv_includes=`eval echo "$withval"` ])
171
172 AC_ARG_WITH(qt-libraries, [ --with-qt-libraries where the Qt library is installed.],
173 [ qt_cv_libraries=`eval echo "$withval"` ])
174
175 dnl pay attention to $QTDIR unless overridden
176 if test -z "$qt_cv_dir"; then
177 qt_cv_dir=$QTDIR
178 fi
179
180 dnl derive inc/lib if needed
181 if test -n "$qt_cv_dir"; then
182 if test -z "$qt_cv_includes"; then
183 qt_cv_includes=$qt_cv_dir/include
184 fi
185 if test -z "$qt_cv_libraries"; then
186 qt_cv_libraries=$qt_cv_dir/lib
187 fi
188 fi
189
190 dnl flags for compilation
191 QT_INCLUDES=
192 QT_LDFLAGS=
193 if test -n "$qt_cv_includes"; then
194 QT_INCLUDES="-isystem $qt_cv_includes"
195 fi
196 if test -n "$qt_cv_libraries"; then
197 QT_LDFLAGS="-L$qt_cv_libraries"
198 fi
199 AC_SUBST(QT_INCLUDES)
200 AC_SUBST(QT_LDFLAGS)
201
202 QT_FIND_MOC
203 MOC=$ac_moc
204 AC_SUBST(MOC)
205 QT_FIND_UIC
206 UIC=$ac_uic
207 AC_SUBST(UIC)
208
209 QT_CHECK_COMPILE
210
211 QT_LIB=$qt_cv_libname;
212 AC_SUBST(QT_LIB)
213
214 if test -n "$qt_cv_libname"; then
215 QT_GET_VERSION
216 fi
217])