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