]> git.lyx.org Git - lyx.git/blob - config/qt4.m4
Show cursor correctly whn loading file
[lyx.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                 if test x$USE_QT5 = xyes ; then
60                         AC_MSG_RESULT([failed, retrying with Qt4])
61                 else
62                         AC_MSG_RESULT([failed])
63                         AC_MSG_ERROR([cannot compile a simple Qt executable. Check you have the right \$QTDIR.])
64                 fi
65         else
66                 AC_MSG_RESULT([$qt_cv_libname])
67         fi
68 ])
69
70
71 AC_DEFUN([QT_FIND_TOOL],
72 [
73         $1=
74         qt_ext=qt4
75         if test "x$USE_QT5" != "xno" ; then
76                 qt_ext=qt5
77         fi
78
79         if test -n "$qt_cv_bin" ; then
80                 AC_PATH_PROGS($1, [$2], [], $qt_cv_bin)
81         elif qtchooser -l 2>/dev/null | grep -q ^$qt_ext\$ >/dev/null ; then
82                 AC_PATH_PROG(qtc_path, qtchooser, [], [$PATH])
83                 AC_PATH_PROG($2_path, $2, [], [$PATH])
84                 qtc_path=`dirname "$qtc_path"`
85                 $2_path=`dirname "$$2_path"`
86                 if test "$qtc_path" = "$$2_path" ; then
87                         AC_CHECK_PROG($1, $2, [$2 -qt=$qt_ext],, [$PATH])
88                 fi
89         fi
90         if test -z "$$1"; then
91                 AC_CHECK_PROGS($1, [$2-$qt_ext $2],[],$PATH)
92         fi
93         if test -z "$$1"; then
94                 AC_MSG_ERROR([cannot find $2 binary.])
95         fi
96 ])
97
98
99 dnl get Qt version we're using
100 AC_DEFUN([QT_GET_VERSION],
101 [
102         AC_CACHE_CHECK([Qt version],lyx_cv_qtversion,
103         [
104                 AC_LANG_CPLUSPLUS
105                 SAVE_CPPFLAGS=$CPPFLAGS
106                 CPPFLAGS="$CPPFLAGS $QT_INCLUDES"
107
108                 cat > conftest.$ac_ext <<EOF
109 #line __oline__ "configure"
110 #include "confdefs.h"
111 #include <qglobal.h>
112 "%%%"QT_VERSION_STR"%%%"
113 EOF
114                 lyx_cv_qtversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
115                         grep '^"%%%"'  2>/dev/null | \
116                         sed -e 's/"%%%"//g' -e 's/"//g'`
117                 rm -f conftest.$ac_ext
118                 CPPFLAGS=$SAVE_CPPFLAGS
119         ])
120
121         QTLIB_VERSION=$lyx_cv_qtversion
122         AC_SUBST(QTLIB_VERSION)
123 ])
124
125 dnl start here
126 AC_DEFUN([QT_DO_IT_ALL],
127 [
128         dnl this variable is precious
129         AC_ARG_VAR(QTDIR, [the place where the Qt files are, e.g. /usr/lib/qt4])
130
131         AC_ARG_WITH(qt-dir, [AC_HELP_STRING([--with-qt-dir], [where the root of Qt is installed])],
132                 [ qt_cv_dir=`eval echo "$withval"/` ])
133
134         AC_ARG_WITH(qt-includes, [AC_HELP_STRING([--with-qt-includes], [where the Qt includes are])],
135                 [ qt_cv_includes=`eval echo "$withval"` ])
136
137         AC_ARG_WITH(qt-libraries, [AC_HELP_STRING([--with-qt-libraries], [where the Qt library is installed])],
138                 [  qt_cv_libraries=`eval echo "$withval"` ])
139
140         dnl pay attention to $QTDIR unless overridden
141         if test -z "$qt_cv_dir"; then
142                 qt_cv_dir=$QTDIR
143         fi
144
145         dnl derive inc/lib if needed
146         if test -n "$qt_cv_dir"; then
147                 if test -z "$qt_cv_includes"; then
148                         qt_cv_includes=$qt_cv_dir/include
149                 fi
150                 if test -z "$qt_cv_libraries"; then
151                         qt_cv_libraries=$qt_cv_dir/lib
152                 fi
153         fi
154
155         dnl compute the binary dir too
156         if test -n "$qt_cv_dir"; then
157                 qt_cv_bin=$qt_cv_dir/bin
158         fi
159
160         dnl Preprocessor flags
161         QT_CPPFLAGS="-DQT_NO_STL -DQT_NO_KEYWORDS"
162         case ${host} in
163         *mingw*) QT_CPPFLAGS="-DQT_DLL $QT_CPPFLAGS";;
164         esac
165         AC_SUBST(QT_CPPFLAGS)
166
167         dnl Check if it possible to do a pkg-config
168         PKG_PROG_PKG_CONFIG
169         if test -n "$PKG_CONFIG" ; then
170                 QT_DO_PKG_CONFIG
171         fi
172         if test "$pkg_failed" != "no" ; then
173                 QT_DO_MANUAL_CONFIG
174         fi
175
176         if test -z "$QT_LIB"; then
177           dnl Try again with Qt4 if configuring for Qt5 fails
178           if test x$USE_QT5 = xyes ; then
179                 USE_QT5=no
180                 AC_SUBST([USE_QT5])
181                 if test -n "$PKG_CONFIG" ; then
182                   QT_DO_PKG_CONFIG
183                 fi
184                 if test "$pkg_failed" != "no" ; then
185                   QT_DO_MANUAL_CONFIG
186                 fi
187                 if test -z "$QT_LIB"; then
188                   AC_MSG_ERROR([cannot find qt libraries.])
189                 fi
190           else
191                 AC_MSG_ERROR([cannot find qt libraries.])
192           fi
193         fi
194
195         dnl Check qt version
196         AS_VERSION_COMPARE($QTLIB_VERSION, $1,
197         [AC_MSG_ERROR([LyX requires at least version $1 of Qt. Only version $QTLIB_VERSION has been found.])
198         ])
199
200         save_CPPFLAGS=$CPPFLAGS
201         CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES"
202         AC_CHECK_HEADER(QtGui/qtgui-config.h,
203           [lyx_qt5_config=QtGui/qtgui-config.h],
204           [lyx_qt5_config=qconfig.h],[-])
205         AC_MSG_CHECKING([whether Qt uses the X Window system])
206         if test x$USE_QT5 = xyes ; then
207           AC_EGREP_CPP(xcb,
208             [#include <$lyx_qt5_config>
209             QT_QPA_DEFAULT_PLATFORM_NAME],
210             [AC_MSG_RESULT(yes)
211              AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])],
212             [AC_MSG_RESULT(no)])
213         else
214           AC_PREPROC_IFELSE([AC_LANG_SOURCE([
215             [#include <qglobal.h>],
216             [#ifndef Q_WS_X11],
217             [#error Fail],
218             [#endif]])],
219             qt_use_x11=yes,
220             qt_use_x11=no)
221           AC_MSG_RESULT($qt_use_x11)
222           if test "x$qt_use_x11" = "xyes"; then
223             QT_LIB="$QT_LIB -lX11"
224           fi
225         fi
226         CPPFLAGS=$save_CPPFLAGS
227
228         QT_FIND_TOOL([QT_MOC], [moc])
229         QT_FIND_TOOL([QT_UIC], [uic])
230         QT_FIND_TOOL([QT_RCC], [rcc])
231
232         dnl Safety check
233         mocqtver=`$QT_MOC -v 2>&1 | sed -e 's/.*\([[0-9]]\.[[0-9]]*\.[[0-9]]\).*/\1/'`
234         if test "x$mocqtver" != "x$QTLIB_VERSION"; then
235                 LYX_WARNING([The found moc compiler is for Qt $mocqtver but the Qt library version is $QTLIB_VERSION.])
236         fi
237 ])
238
239 AC_DEFUN([QT_DO_PKG_CONFIG],
240 [
241         dnl tell pkg-config to look also in $qt_cv_dir/lib.
242         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
243         if test -n "$qt_cv_dir" ; then
244           PKG_CONFIG_PATH=$qt_cv_dir/lib:$qt_cv_dir/lib/pkgconfig:$PKG_CONFIG_PATH
245           export PKG_CONFIG_PATH
246         fi
247         qt_corelibs="QtCore"
248         qt_guilibs="QtCore QtGui QtSvg"
249         if test "x$USE_QT5" != "xno" ; then
250                 qt_corelibs="Qt5Core"
251                 qt_guilibs="Qt5Core Qt5Concurrent Qt5Gui Qt5Svg Qt5Widgets"
252                 lyx_use_x11extras=false
253                 PKG_CHECK_EXISTS(Qt5X11Extras, [lyx_use_x11extras=true], [])
254                 if $lyx_use_x11extras; then
255                         qt_guilibs="$qt_guilibs Qt5X11Extras xcb"
256                         AC_DEFINE(HAVE_QT5_X11_EXTRAS, 1,
257                                 [Define if you have the Qt5X11Extras module])
258                 fi
259                 lyx_use_winextras=false
260                 PKG_CHECK_EXISTS(Qt5WinExtras, [lyx_use_winextras=true], [])
261                 if $lyx_use_winextras; then
262                         qt_guilibs="$qt_guilibs Qt5WinExtras"
263                 fi
264                 lyx_use_macextras=false
265                 PKG_CHECK_EXISTS(Qt5MacExtras, [lyx_use_macextras=true], [])
266                 if $lyx_use_macextras; then
267                         qt_guilibs="$qt_guilibs Qt5MacExtras"
268                 fi
269         fi
270         PKG_CHECK_MODULES(QT_CORE, $qt_corelibs,,[:])
271         if test "$pkg_failed" = "no" ; then
272                 QT_CORE_INCLUDES=$QT_CORE_CFLAGS
273                 AC_SUBST(QT_CORE_INCLUDES)
274                 QT_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_corelibs`
275                 AC_SUBST(QT_CORE_LDFLAGS)
276                 QT_CORE_LIB=`$PKG_CONFIG --libs-only-l $qt_corelibs`
277                 AC_SUBST(QT_CORE_LIB)
278         fi
279         PKG_CHECK_MODULES(QT_FRONTEND, $qt_guilibs,,[:])
280         if test "$pkg_failed" = "no" ; then
281                 QT_INCLUDES=$QT_FRONTEND_CFLAGS
282                 dnl QT_LDFLAGS=$QT_FRONTEND_LIBS
283                 QT_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_guilibs`
284                 AC_SUBST(QT_INCLUDES)
285                 AC_SUBST(QT_LDFLAGS)
286                 QTLIB_VERSION=`$PKG_CONFIG --modversion $qt_corelibs`
287                 AC_SUBST(QTLIB_VERSION)
288                 QT_LIB=`$PKG_CONFIG --libs-only-l $qt_guilibs`
289                 AC_SUBST(QT_LIB)
290                 dnl LIBS="$LIBS `$PKG_CONFIG --libs-only-other $qt_guilibs`"
291         fi
292         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
293         dnl Actually, the values of QT_LIB and QT_CORE_LIB can be completely
294         dnl wrong on OS X, where everything goes to --libs-only-other.
295         dnl As a quick workaround, let us assign better values. A better patch
296         dnl exists for next cycle.
297         QT_CORE_LIB=$QT_CORE_LIBS
298         QT_CORE_LDFLAGS=
299         QT_LIB=$QT_FRONTEND_LIBS
300         QT_LDFLAGS=
301 ])
302
303 AC_DEFUN([QT_DO_MANUAL_CONFIG],
304 [
305         dnl Check for X libraries
306         case ${host} in
307         *mingw*) ;;
308         *) \
309           AC_PATH_X \
310           AC_PATH_XTRA \
311         ;;
312         esac
313         case $have_x in
314             yes) LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
315                  CPPFLAGS="$CPPFLAGS $X_CFLAGS";;
316              no) AC_MSG_ERROR([cannot find X window libraries and/or headers.]);;
317         disable) ;;
318         esac
319
320         dnl flags for compilation
321         QT_INCLUDES=
322         QT_LDFLAGS=
323         QT_CORE_INCLUDES=
324         QT_CORE_LDFLAGS=
325         if test -n "$qt_cv_includes"; then
326                 QT_INCLUDES="-I$qt_cv_includes"
327                 for i in Qt QtCore QtGui QtWidgets QtSvg QtConcurrent QtMacExtras; do
328                         QT_INCLUDES="$QT_INCLUDES -I$qt_cv_includes/$i"
329                 done
330                 QT_CORE_INCLUDES="-I$qt_cv_includes -I$qt_cv_includes/QtCore"
331         fi
332         case "$qt_cv_libraries" in
333         *framework*)
334                 QT_LDFLAGS="-F$qt_cv_libraries"
335                 QT_CORE_LDFLAGS="-F$qt_cv_libraries"
336                 ;;
337         "")
338                 ;;
339         *)
340                 QT_LDFLAGS="-L$qt_cv_libraries"
341                 QT_CORE_LDFLAGS="-L$qt_cv_libraries"
342                 ;;
343         esac
344         AC_SUBST(QT_INCLUDES)
345         AC_SUBST(QT_CORE_INCLUDES)
346         AC_SUBST(QT_LDFLAGS)
347         AC_SUBST(QT_CORE_LDFLAGS)
348
349         QT_CHECK_COMPILE
350
351         QT_LIB=$qt_cv_libname;
352         AC_SUBST(QT_LIB)
353         AC_SUBST(QT_CORE_LIB)
354
355         if test -n "$qt_cv_libname"; then
356                 QT_GET_VERSION
357         fi
358 ])