]> git.lyx.org Git - lyx.git/blob - config/qt4.m4
Make libQtCore a support library like boost and implement encoding conversion
[lyx.git] / config / qt4.m4
1 dnl check a particular libname
2 AC_DEFUN([QT4_TRY_LINK],
3 [
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"
19 ])
20
21 dnl check we can do a compile
22 AC_DEFUN([QT4_CHECK_COMPILE],
23 [
24         AC_MSG_CHECKING([for Qt 4 library name])
25
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                 for libname in '-lQtCore -lQtGui' \
40                                '-lQtCore4 -lQtGui4'
41                 do
42                         QT4_TRY_LINK($libname)
43                         if test -n "$qt4_cv_libname"; then
44                                 break;
45                         fi
46                 done
47                 CXXFLAGS=$SAVE_CXXFLAGS
48         ])
49
50         if test -z "$qt4_cv_libname"; then
51                 AC_MSG_RESULT([failed])
52                 if test "$FATAL" = 1 ; then
53                         AC_MSG_ERROR([Cannot compile a simple Qt 4 executable. Check you have the right \$QT4DIR !])
54                 fi
55         else
56                 AC_MSG_RESULT([$qt4_cv_libname])
57         fi
58 ])
59
60 dnl get Qt version we're using
61 AC_DEFUN([QT4_GET_VERSION],
62 [
63         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
64         [
65                 AC_LANG_CPLUSPLUS
66                 SAVE_CPPFLAGS=$CPPFLAGS
67                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
68
69                 cat > conftest.$ac_ext <<EOF
70 #line __oline__ "configure"
71 #include "confdefs.h"
72 #include <qglobal.h>
73 "%%%"QT_VERSION_STR"%%%"
74 EOF
75                 lyx_cv_qt4version=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
76                         grep '^"%%%"'  2>/dev/null | \
77                         sed -e 's/"%%%"//g' -e 's/"//g'`
78                 rm -f conftest.$ac_ext
79                 CPPFLAGS=$SAVE_CPPFLAGS
80         ])
81
82         QT4_VERSION=$lyx_cv_qt4version
83         AC_SUBST(QT4_VERSION)
84 ])
85
86 dnl start here
87 AC_DEFUN([QT4_DO_IT_ALL],
88 [
89         dnl this variable is precious
90         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
91
92         dnl Please leave this alone. I use this file in
93         dnl oprofile.
94         FATAL=0
95
96         AC_ARG_WITH(qt4-dir, [  --with-qt4-dir           where the root of Qt 4 is installed ],
97                 [ qt4_cv_dir=`eval echo "$withval"/` ])
98
99         AC_ARG_WITH(qt4-includes, [  --with-qt4-includes      where the Qt 4 includes are. ],
100                 [ qt4_cv_includes=`eval echo "$withval"` ])
101
102         AC_ARG_WITH(qt4-libraries, [  --with-qt4-libraries     where the Qt 4 library is installed.],
103                 [  qt4_cv_libraries=`eval echo "$withval"` ])
104
105         dnl pay attention to $QT4DIR unless overridden
106         if test -z "$qt4_cv_dir"; then
107                 qt4_cv_dir=$QT4DIR
108         fi
109
110         dnl derive inc/lib if needed
111         if test -n "$qt4_cv_dir"; then
112                 if test -z "$qt4_cv_includes"; then
113                         qt4_cv_includes=$qt4_cv_dir/include
114                 fi
115                 if test -z "$qt4_cv_libraries"; then
116                         qt4_cv_libraries=$qt4_cv_dir/lib
117                 fi
118         fi
119
120         dnl compute the binary dir too
121         if test -n "$qt4_cv_dir"; then
122                 qt4_cv_bin=$qt4_cv_dir/bin
123         fi
124
125         dnl Preprocessor flags
126         QT4_CPPFLAGS="-DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_STL -DQT_NO_KEYWORDS"
127         case ${host} in
128         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
129         *cygwin*)
130         if test "x$with_x" = xno ; then
131                 QT4_CPPFLAGS="$QT4_CPPFLAGS -DQ_CYGWIN_WIN"
132         fi;;
133         esac
134         AC_SUBST(QT4_CPPFLAGS)
135
136         dnl Check if it possible to do a pkg-config
137         QT4_DO_PKG_CONFIG
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 ])
144
145 AC_DEFUN([QT4_DO_PKG_CONFIG],
146 [
147         PKG_PROG_PKG_CONFIG
148         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
149         if test -n "$qt4_cv_dir" ; then
150           PKG_CONFIG_PATH=$qt4_cv_dir/lib:$PKG_CONFIG_PATH
151           export PKG_CONFIG_PATH
152         fi
153         PKG_CHECK_MODULES(QT4_CORE, QtCore)
154         if test "$pkg_failed" == "no" ; then
155                 QT4_CORE_INCLUDES=$QT4_CORE_CFLAGS
156                 AC_SUBST(QT4_CORE_INCLUDES)
157                 QT4_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore`
158                 AC_SUBST(QT4_CORE_LDFLAGS)
159                 QT4_CORE_LIB=`$PKG_CONFIG --libs-only-l QtCore`
160                 AC_SUBST(QT4_CORE_LIB)
161         fi
162         PKG_CHECK_MODULES(QT4_FRONTEND, QtCore QtGui)
163         if test "$pkg_failed" == "no" ; then
164                 QT4_INCLUDES=$QT4_FRONTEND_CFLAGS
165                 dnl QT4_LDFLAGS=$QT4_FRONTEND_LIBS
166                 QT4_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore QtGui`
167                 AC_SUBST(QT4_INCLUDES)
168                 AC_SUBST(QT4_LDFLAGS)
169                 QT4_VERSION=`$PKG_CONFIG --modversion QtCore`
170                 AC_SUBST(QT4_VERSION)
171                 QT4_LIB=`$PKG_CONFIG --libs-only-l QtCore QtGui`
172                 AC_SUBST(QT4_LIB)
173         fi
174         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
175 ])
176
177 AC_DEFUN([QT4_DO_MANUAL_CONFIG],
178 [
179         dnl flags for compilation
180         QT4_INCLUDES=
181         QT4_LDFLAGS=
182         QT4_CORE_INCLUDES=
183         QT4_CORE_LDFLAGS=
184         if test -n "$qt4_cv_includes"; then
185                 QT4_INCLUDES="-I$qt4_cv_includes"
186                 for i in Qt QtCore QtGui; do
187                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
188                 done
189                 QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore"
190         fi
191         if test -n "$qt4_cv_libraries"; then
192                 QT4_LDFLAGS="-L$qt4_cv_libraries"
193                 QT4_CORE_LDFLAGS="-L$qt4_cv_libraries"
194         fi
195         AC_SUBST(QT4_INCLUDES)
196         AC_SUBST(QT4_CORE_INCLUDES)
197         AC_SUBST(QT4_LDFLAGS)
198         AC_SUBST(QT4_CORE_LDFLAGS)
199
200         QT4_CHECK_COMPILE
201
202         QT4_LIB=$qt4_cv_libname;
203         AC_SUBST(QT4_LIB)
204         AC_SUBST(QT4_CORE_LIB)
205
206         if test -n "$qt4_cv_libname"; then
207                 QT4_GET_VERSION
208         fi
209 ])