]> git.lyx.org Git - features.git/blob - config/qt4.m4
0e357a44de7f449349be8bf1e53c2c041d2fd36c
[features.git] / config / qt4.m4
1 dnl check a particular libname
2 AC_DEFUN([QT_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         qt_cv_libname=$1,
17         )
18         LIBS="$SAVE_LIBS"
19 ])
20
21 dnl check we can do a compile
22 AC_DEFUN([QT_CHECK_COMPILE],
23 [
24         AC_MSG_CHECKING([for Qt library name])
25
26         AC_CACHE_VAL(qt_cv_libname,
27         [
28                 AC_LANG_CPLUSPLUS
29                 SAVE_CXXFLAGS=$CXXFLAGS
30                 CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS"
31                 qt_corelibs="-lQtCore -lQtCore4"
32                 qt_guilibs="'-lQtCore -lQtGui' '-lQtCore4 -lQtGui4'"
33                 if test $USE_QT5 = "yes" ; then
34                     qt_corelibs="-lQt5Core"
35                     qt_guilibs="-lQt5Core -lQt5Concurrent -lQt5Gui -lQt5Svg -lQt5Widgets"
36                 fi
37                 for libname in $qt_corelibs '-framework QtCore'
38                 do
39                         QT_TRY_LINK($libname)
40                         if test -n "$qt_cv_libname"; then
41                                 QT_CORE_LIB="$qt_cv_libname"
42                                 break;
43                         fi
44                 done
45                 qt_cv_libname=
46                 for libname in $qt_guilibs \
47                                '-framework QtCore -framework QtConcurrent -framework QtSvg -framework QtWidgets -framework QtMacExtras -framework QtGui'\
48                                '-framework QtCore -framework QtGui'
49                 do
50                         QT_TRY_LINK($libname)
51                         if test -n "$qt_cv_libname"; then
52                                 break;
53                         fi
54                 done
55                 CXXFLAGS=$SAVE_CXXFLAGS
56         ])
57
58         if test -z "$qt_cv_libname"; then
59                 AC_MSG_RESULT([failed])
60                 AC_MSG_ERROR([cannot compile a simple Qt executable. Check you have the right \$QTDIR.])
61         else
62                 AC_MSG_RESULT([$qt_cv_libname])
63         fi
64 ])
65
66
67 AC_DEFUN([QT_FIND_TOOL],
68 [
69         $1=
70         qt_ext=qt4
71         if test "x$USE_QT5" != "xno" ; then
72                 qt_ext=qt5
73         fi
74
75         if test -n "$qt_cv_bin" ; then
76                 AC_PATH_PROGS($1, [$2], [], $qt_cv_bin)
77         elif qtchooser -l 2>/dev/null | grep -q ^$qt_ext\$ >/dev/null ; then
78                 AC_CHECK_PROG($1, $2, [$2 -qt=$qt_ext],, [$PATH])
79         fi
80         if test -z "$$1"; then
81                 AC_CHECK_PROGS($1, [$2-$qt_ext $2],[],$PATH)
82         fi
83         if test -z "$$1"; then
84                 AC_MSG_ERROR([cannot find $2 binary.])
85         fi
86 ])
87
88
89 dnl get Qt version we're using
90 AC_DEFUN([QT_GET_VERSION],
91 [
92         AC_CACHE_CHECK([Qt version],lyx_cv_qtversion,
93         [
94                 AC_LANG_CPLUSPLUS
95                 SAVE_CPPFLAGS=$CPPFLAGS
96                 CPPFLAGS="$CPPFLAGS $QT_INCLUDES"
97
98                 cat > conftest.$ac_ext <<EOF
99 #line __oline__ "configure"
100 #include "confdefs.h"
101 #include <qglobal.h>
102 "%%%"QT_VERSION_STR"%%%"
103 EOF
104                 lyx_cv_qtversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
105                         grep '^"%%%"'  2>/dev/null | \
106                         sed -e 's/"%%%"//g' -e 's/"//g'`
107                 rm -f conftest.$ac_ext
108                 CPPFLAGS=$SAVE_CPPFLAGS
109         ])
110
111         QTLIB_VERSION=$lyx_cv_qtversion
112         AC_SUBST(QTLIB_VERSION)
113 ])
114
115 dnl start here
116 AC_DEFUN([QT_DO_IT_ALL],
117 [
118         dnl this variable is precious
119         AC_ARG_VAR(QTDIR, [the place where the Qt files are, e.g. /usr/lib/qt4])
120
121         AC_ARG_WITH(qt-dir, [AC_HELP_STRING([--with-qt-dir], [where the root of Qt is installed])],
122                 [ qt_cv_dir=`eval echo "$withval"/` ])
123
124         AC_ARG_WITH(qt-includes, [AC_HELP_STRING([--with-qt-includes], [where the Qt includes are])],
125                 [ qt_cv_includes=`eval echo "$withval"` ])
126
127         AC_ARG_WITH(qt-libraries, [AC_HELP_STRING([--with-qt-libraries], [where the Qt library is installed])],
128                 [  qt_cv_libraries=`eval echo "$withval"` ])
129
130         dnl pay attention to $QTDIR unless overridden
131         if test -z "$qt_cv_dir"; then
132                 qt_cv_dir=$QTDIR
133         fi
134
135         dnl derive inc/lib if needed
136         if test -n "$qt_cv_dir"; then
137                 if test -z "$qt_cv_includes"; then
138                         qt_cv_includes=$qt_cv_dir/include
139                 fi
140                 if test -z "$qt_cv_libraries"; then
141                         qt_cv_libraries=$qt_cv_dir/lib
142                 fi
143         fi
144
145         dnl compute the binary dir too
146         if test -n "$qt_cv_dir"; then
147                 qt_cv_bin=$qt_cv_dir/bin
148         fi
149
150         dnl Preprocessor flags
151         QT_CPPFLAGS="-DQT_NO_STL -DQT_NO_KEYWORDS"
152         case ${host} in
153         *mingw*) QT_CPPFLAGS="-DQT_DLL $QT_CPPFLAGS";;
154         esac
155         AC_SUBST(QT_CPPFLAGS)
156
157         dnl Check if it possible to do a pkg-config
158         PKG_PROG_PKG_CONFIG
159         if test -n "$PKG_CONFIG" ; then
160                 QT_DO_PKG_CONFIG
161         fi
162         if test "$pkg_failed" != "no" ; then
163                 QT_DO_MANUAL_CONFIG
164         fi
165
166         if test -z "$QT_LIB"; then
167           AC_MSG_ERROR([cannot find qt libraries.])
168         fi
169
170         dnl Check qt version
171         AS_VERSION_COMPARE($QTLIB_VERSION, $1,
172         [AC_MSG_ERROR([LyX requires at least version $1 of Qt. Only version $QTLIB_VERSION has been found.])
173         ])
174
175         if test x$USE_QT5 = xyes ; then
176           save_CPPFLAGS=$CPPFLAGS
177           AC_MSG_CHECKING([whether Qt uses the X Window system])
178           CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES"
179           AC_EGREP_CPP(xcb,
180             [#include <qconfig.h>
181             QT_QPA_DEFAULT_PLATFORM_NAME],
182             [AC_MSG_RESULT(yes)
183              AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])],
184             [AC_MSG_RESULT(no)])
185           CPPFLAGS=$save_CPPFLAGS
186         fi
187
188         QT_FIND_TOOL([QT_MOC], [moc])
189         QT_FIND_TOOL([QT_UIC], [uic])
190         QT_FIND_TOOL([QT_RCC], [rcc])
191
192         dnl Safety check
193         mocqtver=`$QT_MOC -v 2>&1 | sed -e 's/.*\([[0-9]]\.[[0-9]]\.[[0-9]]\).*/\1/'`
194         if test "x$mocqtver" != "x$QTLIB_VERSION"; then
195                 LYX_WARNING([The found moc compiler is for Qt $mocqtver but the Qt library version is $QTLIB_VERSION.])
196         fi
197 ])
198
199 AC_DEFUN([QT_DO_PKG_CONFIG],
200 [
201         dnl tell pkg-config to look also in $qt_cv_dir/lib.
202         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
203         if test -n "$qt_cv_dir" ; then
204           PKG_CONFIG_PATH=$qt_cv_dir/lib:$qt_cv_dir/lib/pkgconfig:$PKG_CONFIG_PATH
205           export PKG_CONFIG_PATH
206         fi
207         qt_corelibs="QtCore"
208         qt_guilibs="QtCore QtGui QtSvg"
209         if test "x$USE_QT5" != "xno" ; then
210                 qt_corelibs="Qt5Core"
211                 qt_guilibs="Qt5Core Qt5Concurrent Qt5Gui Qt5Svg Qt5Widgets"
212                 lyx_use_winextras=false
213                 PKG_CHECK_EXISTS(Qt5WinExtras, [lyx_use_winextras=true], [])
214                 if $lyx_use_winextras; then
215                         qt_guilibs="$qt_guilibs Qt5WinExtras"
216                 fi
217                 lyx_use_macextras=false
218                 PKG_CHECK_EXISTS(Qt5MacExtras, [lyx_use_macextras=true], [])
219                 if $lyx_use_macextras; then
220                         qt_guilibs="$qt_guilibs Qt5MacExtras"
221                 fi
222         fi
223         PKG_CHECK_MODULES(QT_CORE, $qt_corelibs,,[:])
224         if test "$pkg_failed" = "no" ; then
225                 QT_CORE_INCLUDES=$QT_CORE_CFLAGS
226                 AC_SUBST(QT_CORE_INCLUDES)
227                 QT_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_corelibs`
228                 AC_SUBST(QT_CORE_LDFLAGS)
229                 QT_CORE_LIB=`$PKG_CONFIG --libs-only-l $qt_corelibs`
230                 AC_SUBST(QT_CORE_LIB)
231         fi
232         PKG_CHECK_MODULES(QT_FRONTEND, $qt_guilibs,,[:])
233         if test "$pkg_failed" = "no" ; then
234                 QT_INCLUDES=$QT_FRONTEND_CFLAGS
235                 dnl QT_LDFLAGS=$QT_FRONTEND_LIBS
236                 QT_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_guilibs`
237                 AC_SUBST(QT_INCLUDES)
238                 AC_SUBST(QT_LDFLAGS)
239                 QTLIB_VERSION=`$PKG_CONFIG --modversion $qt_corelibs`
240                 AC_SUBST(QTLIB_VERSION)
241                 QT_LIB=`$PKG_CONFIG --libs-only-l $qt_guilibs`
242                 AC_SUBST(QT_LIB)
243                 dnl LIBS="$LIBS `$PKG_CONFIG --libs-only-other $qt_guilibs`"
244         fi
245         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
246         dnl Actually, the values of QT_LIB and QT_CORE_LIB can be completely
247         dnl wrong on OS X, where everything goes to --libs-only-other.
248         dnl As a quick workaround, let us assign better values. A better patch
249         dnl exists for next cycle.
250         QT_CORE_LIB=$QT_CORE_LIBS
251         QT_CORE_LDFLAGS=
252         QT_LIB=$QT_FRONTEND_LIBS
253         QT_LDFLAGS=
254 ])
255
256 AC_DEFUN([QT_DO_MANUAL_CONFIG],
257 [
258         dnl Check for X libraries
259         case ${host} in
260         *mingw*) ;;
261         *) \
262           AC_PATH_X \
263           AC_PATH_XTRA \
264         ;;
265         esac
266         case $have_x in
267             yes) LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
268                  CPPFLAGS="$CPPFLAGS $X_CFLAGS";;
269              no) AC_MSG_ERROR([cannot find X window libraries and/or headers.]);;
270         disable) ;;
271         esac
272
273         dnl flags for compilation
274         QT_INCLUDES=
275         QT_LDFLAGS=
276         QT_CORE_INCLUDES=
277         QT_CORE_LDFLAGS=
278         if test -n "$qt_cv_includes"; then
279                 QT_INCLUDES="-I$qt_cv_includes"
280                 for i in Qt QtCore QtGui QtWidgets QtSvg QtConcurrent QtMacExtras; do
281                         QT_INCLUDES="$QT_INCLUDES -I$qt_cv_includes/$i"
282                 done
283                 QT_CORE_INCLUDES="-I$qt_cv_includes -I$qt_cv_includes/QtCore"
284         fi
285         case "$qt_cv_libraries" in
286         *framework*)
287                 QT_LDFLAGS="-F$qt_cv_libraries"
288                 QT_CORE_LDFLAGS="-F$qt_cv_libraries"
289                 ;;
290         "")
291                 ;;
292         *)
293                 QT_LDFLAGS="-L$qt_cv_libraries"
294                 QT_CORE_LDFLAGS="-L$qt_cv_libraries"
295                 ;;
296         esac
297         AC_SUBST(QT_INCLUDES)
298         AC_SUBST(QT_CORE_INCLUDES)
299         AC_SUBST(QT_LDFLAGS)
300         AC_SUBST(QT_CORE_LDFLAGS)
301
302         QT_CHECK_COMPILE
303
304         QT_LIB=$qt_cv_libname;
305         AC_SUBST(QT_LIB)
306         AC_SUBST(QT_CORE_LIB)
307
308         if test -n "$qt_cv_libname"; then
309                 QT_GET_VERSION
310         fi
311 ])