]> git.lyx.org Git - lyx.git/blob - config/qt.m4
9e226aa19920b755de44066842e047ffb672790d
[lyx.git] / config / qt.m4
1 dnl find a binary in the path
2 AC_DEFUN(QT_FIND_PATH,
3 [
4         AC_MSG_CHECKING([for $1])
5         AC_CACHE_VAL(qt_cv_path_$1,
6         [
7                 qt_cv_path_$1="NONE"
8                 if test -n "$$2"; then
9                         qt_cv_path_$1="$$2";
10                 else
11                         dirs="$3"
12                         qt_save_IFS=$IFS
13                         IFS=':'
14                         for dir in $PATH; do
15                                 dirs="$dirs $dir"
16                         done
17                         IFS=$qt_save_IFS
18  
19                         for dir in $dirs; do
20                                 if test -x "$dir/$1"; then
21                                         if test -n "$5"; then
22                                                 evalstr="$dir/$1 $5 2>&1 "
23                                                 if eval $evalstr; then
24                                                         qt_cv_path_$1="$dir/$1"
25                                                         break
26                                                 fi
27                                         else
28                                                 qt_cv_path_$1="$dir/$1"
29                                                 break
30                                         fi
31                                 fi
32                         done
33                 fi
34         ])
35  
36         if test -z "$qt_cv_path_$1" || test "$qt_cv_path_$1" = "NONE"; then
37                 AC_MSG_RESULT(not found)
38                 $4
39         else
40                 AC_MSG_RESULT($qt_cv_path_$1)
41                 $2=$qt_cv_path_$1
42         fi
43 ])
44
45 dnl Find the uic compiler on the path or in qt_cv_dir
46 AC_DEFUN(QT_FIND_UIC,
47 [
48         QT_FIND_PATH(uic, ac_uic, $qt_cv_dir/bin)
49         if test -z "$ac_uic" -a "$FATAL" = 1; then
50                 AC_MSG_ERROR([uic binary not found in \$PATH or $qt_cv_dir/bin !])
51         fi
52 ])
53  
54 dnl Find the right moc in path/qt_cv_dir
55 AC_DEFUN(QT_FIND_MOC,
56 [
57         QT_FIND_PATH(moc2, ac_moc2, $qt_cv_dir/bin)
58         QT_FIND_PATH(moc, ac_moc1, $qt_cv_dir/bin)
59
60         if test -n "$ac_moc1" -a -n "$ac_moc2"; then
61                 dnl found both. Prefer Qt3's if it exists else moc2
62                 $ac_moc1 -v 2>&1 | grep "Qt 3" >/dev/null
63                 if test "$?" = 0; then
64                         ac_moc=$ac_moc1;
65                 else
66                         ac_moc=$ac_moc2;
67                 fi
68         else
69                 if test -n "$ac_moc1"; then
70                         ac_moc=$ac_moc1;
71                 else
72                         ac_moc=$ac_moc2;
73                 fi
74         fi
75
76         if test -z "$ac_moc"  -a "$FATAL" = 1; then
77                 AC_MSG_ERROR([moc binary not found in \$PATH or $qt_cv_dir/bin !])
78         fi
79 ])
80
81 dnl check a particular libname
82 AC_DEFUN(QT_TRY_LINK,
83 [
84         CXXFLAGS="$BASE_CXXFLAGS $1"
85         AC_TRY_LINK([
86         #include <qglobal.h>
87         #include <qstring.h>
88                 ],
89         [
90         QString s("mangle_failure");
91         #if (QT_VERSION < 221)
92         break_me_(\\\);
93         #endif
94         ],
95         qt_cv_libname=$1,
96         )
97         CXXFLAGS="$BASE_CXXFLAGS"
98 ])
99  
100 dnl check we can do a compile
101 AC_DEFUN(QT_CHECK_COMPILE,
102 [
103         AC_MSG_CHECKING([for Qt library name])
104  
105         AC_CACHE_VAL(qt_cv_libname,
106         [
107                 AC_LANG_CPLUSPLUS
108                 SAVE_CXXFLAGS=$CXXFLAGS
109                 BASE_CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS" 
110
111                 for libname in -lqt3 -lqt2 -lqt -lqt-mt;
112                 do
113                         QT_TRY_LINK($libname)
114                         if test -n "$qt_cv_libname"; then
115                                 break;
116                         fi
117                 done
118
119                 CXXFLAGS=$SAVE_CXXFLAGS
120         ])
121
122         if test -z "$qt_cv_libname"; then
123                 AC_MSG_RESULT([failed]) 
124                 if test "$FATAL" = 1 ; then
125                         AC_MSG_ERROR([Cannot compile a simple Qt executable. Check you have the right \$QTDIR !])
126                 fi
127         else
128                 AC_MSG_RESULT([$qt_cv_libname])
129         fi
130 ])
131
132 dnl start here 
133 AC_DEFUN(QT_DO_IT_ALL,
134 [
135         dnl Please leave this alone. I use this file in
136         dnl oprofile.
137         FATAL=1
138
139         AC_ARG_WITH(qt-dir, [  --with-qt-dir           where the root of Qt is installed ],
140                 [ qt_cv_dir=`eval echo "$withval"/` ])
141          
142         AC_ARG_WITH(qt-includes, [  --with-qt-includes      where the Qt includes are. ],
143                 [ qt_cv_includes=`eval echo "$withval"` ])
144  
145         AC_ARG_WITH(qt-libraries, [  --with-qt-libraries     where the Qt library is installed.],
146                 [  qt_cv_libraries=`eval echo "$withval"` ])
147
148         dnl pay attention to $QTDIR unless overridden
149         if test -z "$qt_cv_dir"; then
150                 qt_cv_dir=$QTDIR
151         fi
152  
153         dnl derive inc/lib if needed
154         if test -n "$qt_cv_dir"; then
155                 if test -z "$qt_cv_includes"; then
156                         qt_cv_includes=$qt_cv_dir/include
157                 fi
158                 if test -z "$qt_cv_libraries"; then
159                         qt_cv_libraries=$qt_cv_dir/lib
160                 fi
161         fi
162
163         dnl flags for compilation
164         QT_INCLUDES=
165         QT_LDFLAGS=
166         if test -n "$qt_cv_includes"; then
167                 QT_INCLUDES="-I$qt_cv_includes"
168         fi
169         if test -n "$qt_cv_libraries"; then
170                 QT_LDFLAGS="-L$qt_cv_libraries"
171         fi
172         AC_SUBST(QT_INCLUDES)
173         AC_SUBST(QT_LDFLAGS)
174  
175         QT_FIND_MOC
176         MOC=$ac_moc
177         AC_SUBST(MOC)
178         QT_FIND_UIC
179         UIC=$ac_uic
180         AC_SUBST(UIC)
181
182         QT_CHECK_COMPILE
183  
184         QT_LIB=$qt_cv_libname;
185         AC_SUBST(QT_LIB)
186 ])