]> git.lyx.org Git - lyx.git/blob - config/qt4.m4
Support autoconf 2.60
[lyx.git] / config / qt4.m4
1 dnl find a binary in the path
2 AC_DEFUN([QT4_FIND_PATH],
3 [
4         AC_MSG_CHECKING([for $1])
5         AC_CACHE_VAL(qt4_cv_path_$1,
6         [
7                 qt4_cv_path_$1="NONE"
8                 if test -n "$$2"; then
9                         qt4_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                                                         qt4_cv_path_$1="$dir/$1"
25                                                         break
26                                                 fi
27                                         else
28                                                 qt4_cv_path_$1="$dir/$1"
29                                                 break
30                                         fi
31                                 fi
32                         done
33                 fi
34         ])
35
36         if test -z "$qt4_cv_path_$1" || test "$qt4_cv_path_$1" = "NONE"; then
37                 AC_MSG_RESULT(not found)
38                 $4
39         else
40                 AC_MSG_RESULT($qt4_cv_path_$1)
41                 $2=$qt4_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_UIC4],
47 [
48         QT4_FIND_PATH(uic, ac_uic4, $qt4_cv_dir/bin)
49
50         if test -z "$ac_uic4" -a "$FATAL" = 1; then
51                 AC_MSG_ERROR([uic 4 binary not found in \$PATH or $qt4_cv_dir/bin !])
52         fi
53 ])
54
55 dnl Find the right moc in path/qt_cv_dir
56 AC_DEFUN([QT_FIND_MOC4],
57 [
58         QT4_FIND_PATH(moc, ac_moc4, $qt4_cv_dir/bin)
59
60         if test -z "$ac_moc4"  -a "$FATAL" = 1; then
61                 AC_MSG_ERROR([moc 4 binary not found in \$PATH or $qt4_cv_dir/bin !])
62         fi
63 ])
64
65 dnl check a particular libname
66 AC_DEFUN([QT4_TRY_LINK],
67 [
68         SAVE_LIBS="$LIBS"
69         LIBS="$LIBS $1"
70         AC_TRY_LINK([
71         #include <qglobal.h>
72         #include <qstring.h>
73                 ],
74         [
75         QString s("mangle_failure");
76         #if (QT_VERSION < 400)
77         break_me_(\\\);
78         #endif
79         ],
80         qt4_cv_libname=$1,
81         )
82         LIBS="$SAVE_LIBS"
83 ])
84
85 dnl check we can do a compile
86 AC_DEFUN([QT4_CHECK_COMPILE],
87 [
88         AC_MSG_CHECKING([for Qt 4 library name])
89
90         AC_CACHE_VAL(qt4_cv_libname,
91         [
92                 AC_LANG_CPLUSPLUS
93                 SAVE_CXXFLAGS=$CXXFLAGS
94                 CXXFLAGS="$CXXFLAGS $QT4_INCLUDES $QT4_LDFLAGS"
95                 for libname in '-lQtCore -lQtGui' \
96                                '-lQtCore4 -lQtGui4'
97                 do
98                         QT4_TRY_LINK($libname)
99                         if test -n "$qt4_cv_libname"; then
100                                 break;
101                         fi
102                 done
103                 CXXFLAGS=$SAVE_CXXFLAGS
104         ])
105
106         if test -z "$qt4_cv_libname"; then
107                 AC_MSG_RESULT([failed])
108                 if test "$FATAL" = 1 ; then
109                         AC_MSG_ERROR([Cannot compile a simple Qt 4 executable. Check you have the right \$QT4DIR !])
110                 fi
111         else
112                 AC_MSG_RESULT([$qt4_cv_libname])
113         fi
114 ])
115
116 dnl get Qt version we're using
117 AC_DEFUN([QT4_GET_VERSION],
118 [
119         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
120         [
121                 AC_LANG_CPLUSPLUS
122                 SAVE_CPPFLAGS=$CPPFLAGS
123                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
124
125                 cat > conftest.$ac_ext <<EOF
126 #line __oline__ "configure"
127 #include "confdefs.h"
128 #include <qglobal.h>
129 "%%%"QT_VERSION_STR"%%%"
130 EOF
131                 lyx_cv_qt4version=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
132                         grep '^"%%%"'  2>/dev/null | \
133                         sed -e 's/"%%%"//g' -e 's/"//g'`
134                 rm -f conftest.$ac_ext
135                 CPPFLAGS=$SAVE_CPPFLAGS
136         ])
137
138         QT4_VERSION=$lyx_cv_qt4version
139         AC_SUBST(QT4_VERSION)
140 ])
141
142 dnl start here
143 AC_DEFUN([QT4_DO_IT_ALL],
144 [
145         dnl this variable is precious
146         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
147
148         dnl Please leave this alone. I use this file in
149         dnl oprofile.
150         FATAL=0
151
152         AC_ARG_WITH(qt4-dir, [  --with-qt4-dir           where the root of Qt 4 is installed ],
153                 [ qt4_cv_dir=`eval echo "$withval"/` ])
154
155         AC_ARG_WITH(qt4-includes, [  --with-qt4-includes      where the Qt 4 includes are. ],
156                 [ qt4_cv_includes=`eval echo "$withval"` ])
157
158         AC_ARG_WITH(qt4-libraries, [  --with-qt4-libraries     where the Qt 4 library is installed.],
159                 [  qt4_cv_libraries=`eval echo "$withval"` ])
160
161         dnl pay attention to $QT4DIR unless overridden
162         if test -z "$qt4_cv_dir"; then
163                 qt4_cv_dir=$QT4DIR
164         fi
165
166         dnl derive inc/lib if needed
167         if test -n "$qt4_cv_dir"; then
168                 if test -z "$qt4_cv_includes"; then
169                         qt4_cv_includes=$qt4_cv_dir/include
170                 fi
171                 if test -z "$qt4_cv_libraries"; then
172                         qt4_cv_libraries=$qt4_cv_dir/lib
173                 fi
174         fi
175
176         dnl flags for compilation
177         QT4_INCLUDES=
178         QT4_LDFLAGS=
179         if test -n "$qt4_cv_includes"; then
180                 QT4_INCLUDES="-I$qt4_cv_includes"
181                 for i in Qt QtCore QtGui; do
182                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
183                 done
184         fi
185         if test -n "$qt4_cv_libraries"; then
186                 QT4_LDFLAGS="-L$qt4_cv_libraries"
187         fi
188         AC_SUBST(QT4_INCLUDES)
189         AC_SUBST(QT4_LDFLAGS)
190
191         dnl Preprocessor flags
192         QT4_CPPFLAGS="-DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_STL -DQT3_SUPPORT -DQT_NO_KEYWORDS"
193         case ${host} in
194         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
195         esac
196         AC_SUBST(QT4_CPPFLAGS)
197
198         if test -z "$MOC4"; then
199                 QT_FIND_MOC4
200                 MOC4=$ac_moc4
201         fi
202         AC_SUBST(MOC4)
203         if test -z "$UIC4"; then
204                 QT_FIND_UIC4
205                 UIC4=$ac_uic4
206         fi
207         AC_SUBST(UIC4)
208
209         QT4_CHECK_COMPILE
210
211         QT4_LIB=$qt4_cv_libname;
212         AC_SUBST(QT4_LIB)
213
214         if test -n "$qt4_cv_libname"; then
215                 QT4_GET_VERSION
216         fi
217 ])