remove obsolete comment.
[lyx.git] / config / qt4.m4
blob79fbbc17ca322af17c0a75477281a9f097f7f237
1 dnl check a particular libname
2 AC_DEFUN([QT4_TRY_LINK],
4         SAVE_LIBS="$LIBS"
5         LIBS="$LIBS $1"
6         AC_TRY_LINK([
7         #include <qglobal.h>
8         #include <qstring.h>
9                 ],
10         [
11         QString s("mangle_failure");
12         #if (QT_VERSION < 400)
13         break_me_(\\\);
14         #endif
15         ],
16         qt4_cv_libname=$1,
17         )
18         LIBS="$SAVE_LIBS"
21 dnl check we can do a compile
22 AC_DEFUN([QT4_CHECK_COMPILE],
24         AC_MSG_CHECKING([for Qt 4 library name])
26         AC_CACHE_VAL(qt4_cv_libname,
27         [
28                 AC_LANG_CPLUSPLUS
29                 SAVE_CXXFLAGS=$CXXFLAGS
30                 CXXFLAGS="$CXXFLAGS $QT4_INCLUDES $QT4_LDFLAGS"
31                 for libname in -lQtCore -lQtCore4
32                 do
33                         QT4_TRY_LINK($libname)
34                         if test -n "$qt4_cv_libname"; then
35                                 QT4_CORE_LIB="$qt4_cv_libname"
36                                 break;
37                         fi
38                 done
39                 qt4_cv_libname=
40                 for libname in '-lQtCore -lQtGui' \
41                                '-lQtCore4 -lQtGui4'
42                 do
43                         QT4_TRY_LINK($libname)
44                         if test -n "$qt4_cv_libname"; then
45                                 break;
46                         fi
47                 done
48                 CXXFLAGS=$SAVE_CXXFLAGS
49         ])
51         if test -z "$qt4_cv_libname"; then
52                 AC_MSG_RESULT([failed])
53                 if test "$FATAL" = 1 ; then
54                         AC_MSG_ERROR([Cannot compile a simple Qt 4 executable. Check you have the right \$QT4DIR !])
55                 fi
56         else
57                 AC_MSG_RESULT([$qt4_cv_libname])
58         fi
61 dnl get Qt version we're using
62 AC_DEFUN([QT4_GET_VERSION],
64         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
65         [
66                 AC_LANG_CPLUSPLUS
67                 SAVE_CPPFLAGS=$CPPFLAGS
68                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
70                 cat > conftest.$ac_ext <<EOF
71 #line __oline__ "configure"
72 #include "confdefs.h"
73 #include <qglobal.h>
74 "%%%"QT_VERSION_STR"%%%"
75 EOF
76                 lyx_cv_qt4version=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
77                         grep '^"%%%"'  2>/dev/null | \
78                         sed -e 's/"%%%"//g' -e 's/"//g'`
79                 rm -f conftest.$ac_ext
80                 CPPFLAGS=$SAVE_CPPFLAGS
81         ])
83         QT4_VERSION=$lyx_cv_qt4version
84         AC_SUBST(QT4_VERSION)
87 dnl start here
88 AC_DEFUN([QT4_DO_IT_ALL],
90         dnl this variable is precious
91         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
93         dnl Please leave this alone. I use this file in
94         dnl oprofile.
95         FATAL=0
97         AC_ARG_WITH(qt4-dir, [  --with-qt4-dir           where the root of Qt 4 is installed ],
98                 [ qt4_cv_dir=`eval echo "$withval"/` ])
100         AC_ARG_WITH(qt4-includes, [  --with-qt4-includes      where the Qt 4 includes are. ],
101                 [ qt4_cv_includes=`eval echo "$withval"` ])
103         AC_ARG_WITH(qt4-libraries, [  --with-qt4-libraries     where the Qt 4 library is installed.],
104                 [  qt4_cv_libraries=`eval echo "$withval"` ])
106         dnl pay attention to $QT4DIR unless overridden
107         if test -z "$qt4_cv_dir"; then
108                 qt4_cv_dir=$QT4DIR
109         fi
111         dnl derive inc/lib if needed
112         if test -n "$qt4_cv_dir"; then
113                 if test -z "$qt4_cv_includes"; then
114                         qt4_cv_includes=$qt4_cv_dir/include
115                 fi
116                 if test -z "$qt4_cv_libraries"; then
117                         qt4_cv_libraries=$qt4_cv_dir/lib
118                 fi
119         fi
121         dnl compute the binary dir too
122         if test -n "$qt4_cv_dir"; then
123                 qt4_cv_bin=$qt4_cv_dir/bin
124         fi
126         dnl Preprocessor flags
127         QT4_CPPFLAGS="-DQT_NO_STL -DQT_NO_KEYWORDS"
128         case ${host} in
129         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
130         esac
131         AC_SUBST(QT4_CPPFLAGS)
133         dnl Check if it possible to do a pkg-config
134         PKG_PROG_PKG_CONFIG
135         if test -n "$PKG_CONFIG" ; then
136                 QT4_DO_PKG_CONFIG
137         fi
138         if test "$pkg_failed" != "no" ; then
139                 QT4_DO_MANUAL_CONFIG
140         fi
141         AC_PATH_PROGS(MOC4, [moc-qt4 moc],[],$qt4_cv_bin:$PATH)
142         AC_PATH_PROGS(UIC4, [uic-qt4 uic],[],$qt4_cv_bin:$PATH)
143         AC_PATH_PROGS(RCC4, [rcc-qt4 rcc],[],$qt4_cv_bin:$PATH)
146 AC_DEFUN([QT4_DO_PKG_CONFIG],
148         dnl tell pkg-config to look also in $qt4_cv_dir/lib.
149         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
150         if test -n "$qt4_cv_dir" ; then
151           PKG_CONFIG_PATH=$qt4_cv_dir/lib:$qt4_cv_dir/lib/pkgconfig:$PKG_CONFIG_PATH
152           export PKG_CONFIG_PATH
153         fi
154         PKG_CHECK_MODULES(QT4_CORE, QtCore,,[:])
155         if test "$pkg_failed" = "no" ; then
156                 QT4_CORE_INCLUDES=$QT4_CORE_CFLAGS
157                 AC_SUBST(QT4_CORE_INCLUDES)
158                 QT4_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore`
159                 AC_SUBST(QT4_CORE_LDFLAGS)
160                 QT4_CORE_LIB=`$PKG_CONFIG --libs-only-l QtCore`
161                 AC_SUBST(QT4_CORE_LIB)
162         fi
163         PKG_CHECK_MODULES(QT4_FRONTEND, QtCore QtGui,,[:])
164         if test "$pkg_failed" = "no" ; then
165                 QT4_INCLUDES=$QT4_FRONTEND_CFLAGS
166                 dnl QT4_LDFLAGS=$QT4_FRONTEND_LIBS
167                 QT4_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore QtGui`
168                 AC_SUBST(QT4_INCLUDES)
169                 AC_SUBST(QT4_LDFLAGS)
170                 QT4_VERSION=`$PKG_CONFIG --modversion QtCore`
171                 AC_SUBST(QT4_VERSION)
172                 QT4_LIB=`$PKG_CONFIG --libs-only-l QtCore QtGui`
173                 AC_SUBST(QT4_LIB)
174                 LIBS="$LIBS `$PKG_CONFIG --libs-only-other QtCore QtGui`"
175         fi
176         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
179 AC_DEFUN([QT4_DO_MANUAL_CONFIG],
181         dnl Check for X libraries
182         AC_PATH_X
183         AC_PATH_XTRA
184         case $have_x in
185             yes) LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
186                  CPPFLAGS="$CPPFLAGS $X_CFLAGS";;
187              no) LYX_ERROR([Cannot find X window libraries and/or headers.]);;
188         disable) ;;
189         esac
191         dnl flags for compilation
192         QT4_INCLUDES=
193         QT4_LDFLAGS=
194         QT4_CORE_INCLUDES=
195         QT4_CORE_LDFLAGS=
196         if test -n "$qt4_cv_includes"; then
197                 QT4_INCLUDES="-I$qt4_cv_includes"
198                 for i in Qt QtCore QtGui; do
199                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
200                 done
201                 QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore"
202         fi
203         if test -n "$qt4_cv_libraries"; then
204                 QT4_LDFLAGS="-L$qt4_cv_libraries"
205                 QT4_CORE_LDFLAGS="-L$qt4_cv_libraries"
206         fi
207         AC_SUBST(QT4_INCLUDES)
208         AC_SUBST(QT4_CORE_INCLUDES)
209         AC_SUBST(QT4_LDFLAGS)
210         AC_SUBST(QT4_CORE_LDFLAGS)
212         QT4_CHECK_COMPILE
214         QT4_LIB=$qt4_cv_libname;
215         AC_SUBST(QT4_LIB)
216         AC_SUBST(QT4_CORE_LIB)
218         if test -n "$qt4_cv_libname"; then
219                 QT4_GET_VERSION
220         fi