]> git.lyx.org Git - lyx.git/blob - config/qt4.m4
update build instructions (Qt 4.2.2 etc.)
[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                 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         ])
50
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
59 ])
60
61 dnl get Qt version we're using
62 AC_DEFUN([QT4_GET_VERSION],
63 [
64         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
65         [
66                 AC_LANG_CPLUSPLUS
67                 SAVE_CPPFLAGS=$CPPFLAGS
68                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
69
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         ])
82
83         QT4_VERSION=$lyx_cv_qt4version
84         AC_SUBST(QT4_VERSION)
85 ])
86
87 dnl start here
88 AC_DEFUN([QT4_DO_IT_ALL],
89 [
90         dnl this variable is precious
91         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
92
93         dnl Please leave this alone. I use this file in
94         dnl oprofile.
95         FATAL=0
96
97         AC_ARG_WITH(qt4-dir, [  --with-qt4-dir           where the root of Qt 4 is installed ],
98                 [ qt4_cv_dir=`eval echo "$withval"/` ])
99
100         AC_ARG_WITH(qt4-includes, [  --with-qt4-includes      where the Qt 4 includes are. ],
101                 [ qt4_cv_includes=`eval echo "$withval"` ])
102
103         AC_ARG_WITH(qt4-libraries, [  --with-qt4-libraries     where the Qt 4 library is installed.],
104                 [  qt4_cv_libraries=`eval echo "$withval"` ])
105
106         dnl pay attention to $QT4DIR unless overridden
107         if test -z "$qt4_cv_dir"; then
108                 qt4_cv_dir=$QT4DIR
109         fi
110
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
120
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
125
126         dnl Preprocessor flags
127         QT4_CPPFLAGS="-DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_STL -DQT_NO_KEYWORDS"
128         case ${host} in
129         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
130         *cygwin*)
131         if test "x$with_x" = xno ; then
132                 QT4_CPPFLAGS="$QT4_CPPFLAGS -DQ_CYGWIN_WIN"
133         fi;;
134         esac
135         AC_SUBST(QT4_CPPFLAGS)
136
137         dnl Check if it possible to do a pkg-config
138         QT4_DO_PKG_CONFIG
139         if test "$pkg_failed" != "no" ; then
140                 QT4_DO_MANUAL_CONFIG
141         fi
142         AC_PATH_PROGS(MOC4, [moc-qt4 moc],[],$qt4_cv_bin:$PATH)
143         AC_PATH_PROGS(UIC4, [uic-qt4 uic],[],$qt4_cv_bin:$PATH)
144 ])
145
146 AC_DEFUN([QT4_DO_PKG_CONFIG],
147 [
148         PKG_PROG_PKG_CONFIG
149         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
150         if test -n "$qt4_cv_dir" ; then
151           PKG_CONFIG_PATH=$qt4_cv_dir/lib:$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         fi
175         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
176 ])
177
178 AC_DEFUN([QT4_DO_MANUAL_CONFIG],
179 [
180         dnl flags for compilation
181         QT4_INCLUDES=
182         QT4_LDFLAGS=
183         QT4_CORE_INCLUDES=
184         QT4_CORE_LDFLAGS=
185         if test -n "$qt4_cv_includes"; then
186                 QT4_INCLUDES="-I$qt4_cv_includes"
187                 for i in Qt QtCore QtGui; do
188                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
189                 done
190                 QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore"
191         fi
192         if test -n "$qt4_cv_libraries"; then
193                 QT4_LDFLAGS="-L$qt4_cv_libraries"
194                 QT4_CORE_LDFLAGS="-L$qt4_cv_libraries"
195         fi
196         AC_SUBST(QT4_INCLUDES)
197         AC_SUBST(QT4_CORE_INCLUDES)
198         AC_SUBST(QT4_LDFLAGS)
199         AC_SUBST(QT4_CORE_LDFLAGS)
200
201         QT4_CHECK_COMPILE
202
203         QT4_LIB=$qt4_cv_libname;
204         AC_SUBST(QT4_LIB)
205         AC_SUBST(QT4_CORE_LIB)
206
207         if test -n "$qt4_cv_libname"; then
208                 QT4_GET_VERSION
209         fi
210 ])