]> git.lyx.org Git - features.git/blob - config/qt4.m4
Qt4 autoconf cleanup.
[features.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 -lQtGui' \
32                                '-lQtCore4 -lQtGui4'
33                 do
34                         QT4_TRY_LINK($libname)
35                         if test -n "$qt4_cv_libname"; then
36                                 break;
37                         fi
38                 done
39                 CXXFLAGS=$SAVE_CXXFLAGS
40         ])
41
42         if test -z "$qt4_cv_libname"; then
43                 AC_MSG_RESULT([failed])
44                 if test "$FATAL" = 1 ; then
45                         AC_MSG_ERROR([Cannot compile a simple Qt 4 executable. Check you have the right \$QT4DIR !])
46                 fi
47         else
48                 AC_MSG_RESULT([$qt4_cv_libname])
49         fi
50 ])
51
52 dnl get Qt version we're using
53 AC_DEFUN([QT4_GET_VERSION],
54 [
55         AC_CACHE_CHECK([Qt 4 version],lyx_cv_qt4version,
56         [
57                 AC_LANG_CPLUSPLUS
58                 SAVE_CPPFLAGS=$CPPFLAGS
59                 CPPFLAGS="$CPPFLAGS $QT4_INCLUDES"
60
61                 cat > conftest.$ac_ext <<EOF
62 #line __oline__ "configure"
63 #include "confdefs.h"
64 #include <qglobal.h>
65 "%%%"QT_VERSION_STR"%%%"
66 EOF
67                 lyx_cv_qt4version=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
68                         grep '^"%%%"'  2>/dev/null | \
69                         sed -e 's/"%%%"//g' -e 's/"//g'`
70                 rm -f conftest.$ac_ext
71                 CPPFLAGS=$SAVE_CPPFLAGS
72         ])
73
74         QT4_VERSION=$lyx_cv_qt4version
75         AC_SUBST(QT4_VERSION)
76 ])
77
78 dnl start here
79 AC_DEFUN([QT4_DO_IT_ALL],
80 [
81         dnl this variable is precious
82         AC_ARG_VAR(QT4DIR, [the place where the Qt 4 files are, e.g. /usr/lib/qt4])
83
84         dnl Please leave this alone. I use this file in
85         dnl oprofile.
86         FATAL=0
87
88         AC_ARG_WITH(qt4-dir, [  --with-qt4-dir           where the root of Qt 4 is installed ],
89                 [ qt4_cv_dir=`eval echo "$withval"/` ])
90
91         AC_ARG_WITH(qt4-includes, [  --with-qt4-includes      where the Qt 4 includes are. ],
92                 [ qt4_cv_includes=`eval echo "$withval"` ])
93
94         AC_ARG_WITH(qt4-libraries, [  --with-qt4-libraries     where the Qt 4 library is installed.],
95                 [  qt4_cv_libraries=`eval echo "$withval"` ])
96
97         dnl pay attention to $QT4DIR unless overridden
98         if test -z "$qt4_cv_dir"; then
99                 qt4_cv_dir=$QT4DIR
100         fi
101
102         dnl derive inc/lib if needed
103         if test -n "$qt4_cv_dir"; then
104                 if test -z "$qt4_cv_includes"; then
105                         qt4_cv_includes=$qt4_cv_dir/include
106                 fi
107                 if test -z "$qt4_cv_libraries"; then
108                         qt4_cv_libraries=$qt4_cv_dir/lib
109                 fi
110         fi
111
112         dnl compute the binary dir too
113         if test -n "$qt4_cv_dir"; then
114                 qt4_cv_bin=$qt4_cv_dir/bin
115         fi
116
117         dnl Preprocessor flags
118         QT4_CPPFLAGS="-DQT_CLEAN_NAMESPACE -DQT_GENUINE_STR -DQT_NO_STL -DQT_NO_KEYWORDS"
119         case ${host} in
120         *mingw*) QT4_CPPFLAGS="-DQT_DLL $QT4_CPPFLAGS";;
121         esac
122         AC_SUBST(QT4_CPPFLAGS)
123
124         dnl Check if it possible to do a pkg-config
125         QT4_DO_PKG_CONFIG
126         if test "$pkg_failed" != "no" ; then
127                 QT4_DO_MANUAL_CONFIG
128         fi
129         AC_PATH_PROGS(MOC4, [moc-qt4 moc],[],$qt4_cv_bin:$PATH)
130         AC_PATH_PROGS(UIC4, [uic-qt4 uic],[],$qt4_cv_bin:$PATH)
131 ])
132
133 AC_DEFUN([QT4_DO_PKG_CONFIG],
134 [
135         PKG_PROG_PKG_CONFIG
136         save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
137         if test -n "$qt4_cv_dir" ; then
138           PKG_CONFIG_PATH=$qt4_cv_dir/lib:$PKG_CONFIG_PATH
139           export PKG_CONFIG_PATH
140         fi
141         PKG_CHECK_MODULES(QT4_FRONTEND, QtCore QtGui)
142         if test "$pkg_failed" == "no" ; then
143                 QT4_INCLUDES=$QT4_FRONTEND_CFLAGS
144                 dnl QT4_LDFLAGS=$QT4_FRONTEND_LIBS
145                 QT4_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore QtGui`
146                 AC_SUBST(QT4_INCLUDES)
147                 AC_SUBST(QT4_LDFLAGS)
148                 QT4_VERSION=`$PKG_CONFIG --modversion QtCore`
149                 AC_SUBST(QT4_VERSION)
150                 QT4_LIB=`$PKG_CONFIG --libs-only-l QtCore QtGui`
151                 AC_SUBST(QT4_LIB)
152         else
153                 QT4_DO_MANUAL_CONFIG
154         fi
155         PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
156 ])
157
158 AC_DEFUN([QT4_DO_MANUAL_CONFIG],
159 [
160         dnl flags for compilation
161         QT4_INCLUDES=
162         QT4_LDFLAGS=
163         if test -n "$qt4_cv_includes"; then
164                 QT4_INCLUDES="-I$qt4_cv_includes"
165                 for i in Qt QtCore QtGui; do
166                         QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
167                 done
168         fi
169         if test -n "$qt4_cv_libraries"; then
170                 QT4_LDFLAGS="-L$qt4_cv_libraries"
171         fi
172         AC_SUBST(QT4_INCLUDES)
173         AC_SUBST(QT4_LDFLAGS)
174
175         QT4_CHECK_COMPILE
176
177         QT4_LIB=$qt4_cv_libname;
178         AC_SUBST(QT4_LIB)
179
180         if test -n "$qt4_cv_libname"; then
181                 QT4_GET_VERSION
182         fi
183 ])