]> git.lyx.org Git - lyx.git/blob - config/qt4.m4
Cmake build: Creating a define for a header file found
[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 '-framework QtCore'
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                                '-framework QtCore -framework QtConcurrent -framework QtWidgets -framework QtGui'\
43                                '-framework QtCore -framework QtGui'
44                 do
45                         QT4_TRY_LINK($libname)
46                         if test -n "$qt4_cv_libname"; then
47                                 break;
48                         fi
49                 done
50                 CXXFLAGS=$SAVE_CXXFLAGS
51         ])
52
53         if test -z "$qt4_cv_libname"; then
54                 AC_MSG_RESULT([failed])
55                 if test "$FATAL" = 1 ; then
56                         AC_MSG_ERROR([Cannot compile a simple Qt 4 executable. Check you have the right \$QT4DIR !])
57                 fi
58         else
59                 AC_MSG_RESULT([$qt4_cv_libname])
60         fi
61 ])
62
63 dnl get Qt version we're using
64 AC_DEFUN([QT4_GET_VERSION],
65 [
66         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
67         [
68                 AC_LANG_CPLUSPLUS
69                 SAVE_CPPFLAGS=$CPPFLAGS
70                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
71
72                 cat > conftest.$ac_ext <<EOF
73 #line __oline__ "configure"
74 #include "confdefs.h"
75 #include <qglobal.h>
76 "%%%"QT_VERSION_STR"%%%"
77 EOF
78                 lyx_cv_qt4version=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
79                         grep '^"%%%"'  2>/dev/null | \
80                         sed -e 's/"%%%"//g' -e 's/"//g'`
81                 rm -f conftest.$ac_ext
82                 CPPFLAGS=$SAVE_CPPFLAGS
83         ])
84
85         QT4_VERSION=$lyx_cv_qt4version
86         AC_SUBST(QT4_VERSION)
87 ])
88
89 dnl start here
90 AC_DEFUN([QT4_DO_IT_ALL],
91 [
92         dnl this variable is precious
93         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
94
95         dnl Please leave this alone. I use this file in
96         dnl oprofile.
97         FATAL=0
98
99         AC_ARG_WITH(qt4-dir, [AC_HELP_STRING([--with-qt4-dir], [where the root of Qt 4 is installed])],
100                 [ qt4_cv_dir=`eval echo "$withval"/` ])
101
102         AC_ARG_WITH(qt4-includes, [AC_HELP_STRING([--with-qt4-includes], [where the Qt 4 includes are])],
103                 [ qt4_cv_includes=`eval echo "$withval"` ])
104
105         AC_ARG_WITH(qt4-libraries, [AC_HELP_STRING([--with-qt4-libraries], [where the Qt 4 library is installed])],
106                 [  qt4_cv_libraries=`eval echo "$withval"` ])
107
108         dnl pay attention to $QT4DIR unless overridden
109         if test -z "$qt4_cv_dir"; then
110                 qt4_cv_dir=$QT4DIR
111         fi
112
113         dnl derive inc/lib if needed
114         if test -n "$qt4_cv_dir"; then
115                 if test -z "$qt4_cv_includes"; then
116                         qt4_cv_includes=$qt4_cv_dir/include
117                 fi
118                 if test -z "$qt4_cv_libraries"; then
119                         qt4_cv_libraries=$qt4_cv_dir/lib
120                 fi
121         fi
122
123         dnl compute the binary dir too
124         if test -n "$qt4_cv_dir"; then
125                 qt4_cv_bin=$qt4_cv_dir/bin
126         fi
127
128         dnl Preprocessor flags
129         QT4_CPPFLAGS="-DQT_NO_STL -DQT_NO_KEYWORDS"
130         case ${host} in
131         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
132         esac
133         AC_SUBST(QT4_CPPFLAGS)
134
135         dnl Check if it possible to do a pkg-config
136         PKG_PROG_PKG_CONFIG
137         if test -n "$PKG_CONFIG" ; then
138                 QT4_DO_PKG_CONFIG
139         fi
140         if test "$pkg_failed" != "no" ; then
141                 QT4_DO_MANUAL_CONFIG
142         fi
143         AC_PATH_PROGS(MOC4, [moc-qt4 moc],[],$qt4_cv_bin:$PATH)
144         AC_PATH_PROGS(UIC4, [uic-qt4 uic],[],$qt4_cv_bin:$PATH)
145         AC_PATH_PROGS(RCC4, [rcc-qt4 rcc],[],$qt4_cv_bin:$PATH)
146         AC_CHECK_PROG(bc_found,[bc],[yes],[no],$PATH)
147 ])
148
149 AC_DEFUN([QT4_DO_PKG_CONFIG],
150 [
151         dnl tell pkg-config to look also in $qt4_cv_dir/lib.
152         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
153         if test -n "$qt4_cv_dir" ; then
154           PKG_CONFIG_PATH=$qt4_cv_dir/lib:$qt4_cv_dir/lib/pkgconfig:$PKG_CONFIG_PATH
155           export PKG_CONFIG_PATH
156         fi
157         PKG_CHECK_MODULES(QT4_CORE, QtCore,,[:])
158         if test "$pkg_failed" = "no" ; then
159                 QT4_CORE_INCLUDES=$QT4_CORE_CFLAGS
160                 AC_SUBST(QT4_CORE_INCLUDES)
161                 QT4_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore`
162                 AC_SUBST(QT4_CORE_LDFLAGS)
163                 QT4_CORE_LIB=`$PKG_CONFIG --libs-only-l QtCore`
164                 AC_SUBST(QT4_CORE_LIB)
165         fi
166         PKG_CHECK_MODULES(QT4_FRONTEND, QtCore QtGui,,[:])
167         if test "$pkg_failed" = "no" ; then
168                 QT4_INCLUDES=$QT4_FRONTEND_CFLAGS
169                 dnl QT4_LDFLAGS=$QT4_FRONTEND_LIBS
170                 QT4_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore QtGui`
171                 AC_SUBST(QT4_INCLUDES)
172                 AC_SUBST(QT4_LDFLAGS)
173                 QT4_VERSION=`$PKG_CONFIG --modversion QtCore`
174                 AC_SUBST(QT4_VERSION)
175                 QT4_LIB=`$PKG_CONFIG --libs-only-l QtCore QtGui`
176                 AC_SUBST(QT4_LIB)
177                 LIBS="$LIBS `$PKG_CONFIG --libs-only-other QtCore QtGui`"
178         fi
179         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
180 ])
181
182 AC_DEFUN([QT4_DO_MANUAL_CONFIG],
183 [
184         dnl Check for X libraries
185         AC_PATH_X
186         AC_PATH_XTRA
187         case $have_x in
188             yes) LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
189                  CPPFLAGS="$CPPFLAGS $X_CFLAGS";;
190              no) LYX_ERROR([Cannot find X window libraries and/or headers.]);;
191         disable) ;;
192         esac
193
194         dnl flags for compilation
195         QT4_INCLUDES=
196         QT4_LDFLAGS=
197         QT4_CORE_INCLUDES=
198         QT4_CORE_LDFLAGS=
199         if test -n "$qt4_cv_includes"; then
200                 QT4_INCLUDES="-I$qt4_cv_includes"
201                 for i in Qt QtCore QtGui QtWidgets QtConcurrent; do
202                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
203                 done
204                 QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore"
205         fi
206         case "$qt4_cv_libraries" in
207         *framework*)
208                 QT4_LDFLAGS="-F$qt4_cv_libraries"
209                 QT4_CORE_LDFLAGS="-F$qt4_cv_libraries"
210                 ;;
211         "")
212                 ;;
213         *)
214                 QT4_LDFLAGS="-L$qt4_cv_libraries"
215                 QT4_CORE_LDFLAGS="-L$qt4_cv_libraries"
216                 ;;
217         esac
218         AC_SUBST(QT4_INCLUDES)
219         AC_SUBST(QT4_CORE_INCLUDES)
220         AC_SUBST(QT4_LDFLAGS)
221         AC_SUBST(QT4_CORE_LDFLAGS)
222
223         QT4_CHECK_COMPILE
224
225         QT4_LIB=$qt4_cv_libname;
226         AC_SUBST(QT4_LIB)
227         AC_SUBST(QT4_CORE_LIB)
228
229         if test -n "$qt4_cv_libname"; then
230                 QT4_GET_VERSION
231         fi
232 ])