root / config / bnv_have_qt.m4 @ 5d69a524
History | View | Annotate | Download (14.2 kB)
| 1 | dnl Available from the GNU Autoconf Macro Archive at: |
|---|---|
| 2 | dnl http://www.gnu.org/software/ac-archive/htmldoc/bnv_have_qt.html |
| 3 | dnl |
| 4 | AC_DEFUN([BNV_HAVE_QT], |
| 5 | [ |
| 6 | dnl THANKS! This code includes bug fixes by: |
| 7 | dnl Tim McClarren. |
| 8 | |
| 9 | AC_REQUIRE([AC_PROG_CXX]) |
| 10 | AC_REQUIRE([AC_PATH_X]) |
| 11 | AC_REQUIRE([AC_PATH_XTRA]) |
| 12 | |
| 13 | AC_MSG_CHECKING(for Qt) |
| 14 | |
| 15 | AC_ARG_WITH([Qt-dir], |
| 16 | [ --with-Qt-dir=DIR DIR is equal to \$QTDIR if you have followed the |
| 17 | installation instructions of Trolltech. Header |
| 18 | files are in DIR/include, binary utilities are |
| 19 | in DIR/bin and the library is in DIR/lib]) |
| 20 | AC_ARG_WITH([Qt-include-dir], |
| 21 | [ --with-Qt-include-dir=DIR |
| 22 | Qt header files are in DIR]) |
| 23 | AC_ARG_WITH([Qt-bin-dir], |
| 24 | [ --with-Qt-bin-dir=DIR Qt utilities such as moc and uic are in DIR]) |
| 25 | AC_ARG_WITH([Qt-lib-dir], |
| 26 | [ --with-Qt-lib-dir=DIR The Qt library is in DIR]) |
| 27 | AC_ARG_WITH([Qt-lib], |
| 28 | [ --with-Qt-lib=LIB Use -lLIB to link with the Qt library]) |
| 29 | if test x"$with_Qt_dir" = x"no" || |
| 30 | test x"$with_Qt_include-dir" = x"no" || |
| 31 | test x"$with_Qt_bin_dir" = x"no" || |
| 32 | test x"$with_Qt_lib_dir" = x"no" || |
| 33 | test x"$with_Qt_lib" = x"no"; then |
| 34 | # user disabled Qt. Leave cache alone. |
| 35 | have_qt="User disabled Qt." |
| 36 | else |
| 37 | # "yes" is a bogus option |
| 38 | if test x"$with_Qt_dir" = xyes; then |
| 39 | with_Qt_dir= |
| 40 | fi |
| 41 | if test x"$with_Qt_include_dir" = xyes; then |
| 42 | with_Qt_include_dir= |
| 43 | fi |
| 44 | if test x"$with_Qt_bin_dir" = xyes; then |
| 45 | with_Qt_bin_dir= |
| 46 | fi |
| 47 | if test x"$with_Qt_lib_dir" = xyes; then |
| 48 | with_Qt_lib_dir= |
| 49 | fi |
| 50 | if test x"$with_Qt_lib" = xyes; then |
| 51 | with_Qt_lib= |
| 52 | fi |
| 53 | # No Qt unless we discover otherwise |
| 54 | have_qt=no |
| 55 | # Check whether we are requested to link with a specific version |
| 56 | if test x"$with_Qt_lib" != x; then |
| 57 | bnv_qt_lib="$with_Qt_lib" |
| 58 | fi |
| 59 | # Check whether we were supplied with an answer already |
| 60 | if test x"$with_Qt_dir" != x; then |
| 61 | have_qt=yes |
| 62 | bnv_qt_dir="$with_Qt_dir" |
| 63 | bnv_qt_include_dir="$with_Qt_dir/include" |
| 64 | bnv_qt_bin_dir="$with_Qt_dir/bin" |
| 65 | bnv_qt_lib_dir="$with_Qt_dir/lib" |
| 66 | # Only search for the lib if the user did not define one already |
| 67 | if test x"$bnv_qt_lib" = x; then |
| 68 | bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p | |
| 69 | sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`" |
| 70 | fi |
| 71 | bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 72 | else |
| 73 | # Use cached value or do search, starting with suggestions from |
| 74 | # the command line |
| 75 | AC_CACHE_VAL(bnv_cv_have_qt, |
| 76 | [ |
| 77 | # We are not given a solution and there is no cached value. |
| 78 | bnv_qt_dir=NO |
| 79 | bnv_qt_include_dir=NO |
| 80 | bnv_qt_lib_dir=NO |
| 81 | if test x"$bnv_qt_lib" = x; then |
| 82 | bnv_qt_lib=NO |
| 83 | fi |
| 84 | BNV_PATH_QT_DIRECT |
| 85 | if test "$bnv_qt_dir" = NO || |
| 86 | test "$bnv_qt_include_dir" = NO || |
| 87 | test "$bnv_qt_lib_dir" = NO || |
| 88 | test "$bnv_qt_lib" = NO; then |
| 89 | # Problem with finding complete Qt. Cache the known absence of Qt. |
| 90 | bnv_cv_have_qt="have_qt=no" |
| 91 | else |
| 92 | # Record where we found Qt for the cache. |
| 93 | bnv_cv_have_qt="have_qt=yes \ |
| 94 | bnv_qt_dir=$bnv_qt_dir \ |
| 95 | bnv_qt_include_dir=$bnv_qt_include_dir \ |
| 96 | bnv_qt_bin_dir=$bnv_qt_bin_dir \ |
| 97 | bnv_qt_LIBS=\"$bnv_qt_LIBS\"" |
| 98 | fi |
| 99 | ])dnl |
| 100 | eval "$bnv_cv_have_qt" |
| 101 | fi # all $bnv_qt_* are set |
| 102 | fi # $have_qt reflects the system status |
| 103 | if test x"$have_qt" = xyes; then |
| 104 | QT_CXXFLAGS="-I$bnv_qt_include_dir" |
| 105 | QT_DIR="$bnv_qt_dir" |
| 106 | QT_LIBS="$bnv_qt_LIBS" |
| 107 | # If bnv_qt_dir is defined, utilities are expected to be in the |
| 108 | # bin subdirectory |
| 109 | if test x"$bnv_qt_dir" != x; then |
| 110 | if test -x "$bnv_qt_dir/bin/uic"; then |
| 111 | QT_UIC="$bnv_qt_dir/bin/uic" |
| 112 | else |
| 113 | # Old versions of Qt don't have uic |
| 114 | QT_UIC= |
| 115 | fi |
| 116 | QT_MOC="$bnv_qt_dir/bin/moc" |
| 117 | else |
| 118 | # Or maybe we are told where to look for the utilities |
| 119 | if test x"$bnv_qt_bin_dir" != x; then |
| 120 | if test -x "$bnv_qt_bin_dir/uic"; then |
| 121 | QT_UIC="$bnv_qt_bin_dir/uic" |
| 122 | else |
| 123 | # Old versions of Qt don't have uic |
| 124 | QT_UIC= |
| 125 | fi |
| 126 | QT_MOC="$bnv_qt_bin_dir/moc" |
| 127 | else |
| 128 | # Last possibility is that they are in $PATH |
| 129 | QT_UIC="`which uic`" |
| 130 | QT_MOC="`which moc`" |
| 131 | fi |
| 132 | fi |
| 133 | # All variables are defined, report the result |
| 134 | AC_MSG_RESULT([$have_qt: |
| 135 | QT_CXXFLAGS=$QT_CXXFLAGS |
| 136 | QT_DIR=$QT_DIR |
| 137 | QT_LIBS=$QT_LIBS |
| 138 | QT_UIC=$QT_UIC |
| 139 | QT_MOC=$QT_MOC]) |
| 140 | else |
| 141 | # Qt was not found |
| 142 | QT_CXXFLAGS= |
| 143 | QT_DIR= |
| 144 | QT_LIBS= |
| 145 | QT_UIC= |
| 146 | QT_MOC= |
| 147 | AC_MSG_RESULT($have_qt) |
| 148 | fi |
| 149 | AC_SUBST(QT_CXXFLAGS) |
| 150 | AC_SUBST(QT_DIR) |
| 151 | AC_SUBST(QT_LIBS) |
| 152 | AC_SUBST(QT_UIC) |
| 153 | AC_SUBST(QT_MOC) |
| 154 | |
| 155 | #### Being paranoid: |
| 156 | if test x"$have_qt" = xyes; then |
| 157 | AC_MSG_CHECKING(correct functioning of Qt installation) |
| 158 | AC_CACHE_VAL(bnv_cv_qt_test_result, |
| 159 | [ |
| 160 | cat > bnv_qt_test.h << EOF |
| 161 | #include <qobject.h> |
| 162 | class Test : public QObject |
| 163 | {
|
| 164 | Q_OBJECT |
| 165 | public: |
| 166 | Test() {}
|
| 167 | ~Test() {}
|
| 168 | public slots: |
| 169 | void receive() {}
|
| 170 | signals: |
| 171 | void send(); |
| 172 | }; |
| 173 | EOF |
| 174 | |
| 175 | cat > bnv_qt_main.$ac_ext << EOF |
| 176 | #include "bnv_qt_test.h" |
| 177 | #include <qapplication.h> |
| 178 | int main( int argc, char **argv ) |
| 179 | {
|
| 180 | QApplication app( argc, argv ); |
| 181 | Test t; |
| 182 | QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) ); |
| 183 | } |
| 184 | EOF |
| 185 | |
| 186 | bnv_cv_qt_test_result="failure" |
| 187 | bnv_try_1="$QT_MOC bnv_qt_test.h -o moc_bnv_qt_test.$ac_ext >/dev/null 2>bnv_qt_test_1.out" |
| 188 | AC_TRY_EVAL(bnv_try_1) |
| 189 | bnv_err_1=`grep -v '^ *+' bnv_qt_test_1.out | grep -v "^bnv_qt_test.h\$"` |
| 190 | if test x"$bnv_err_1" != x; then |
| 191 | echo "$bnv_err_1" >&AC_FD_CC |
| 192 | echo "configure: could not run $QT_MOC on:" >&AC_FD_CC |
| 193 | cat bnv_qt_test.h >&AC_FD_CC |
| 194 | else |
| 195 | bnv_try_2="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o moc_bnv_qt_test.o moc_bnv_qt_test.$ac_ext >/dev/null 2>bnv_qt_test_2.out" |
| 196 | AC_TRY_EVAL(bnv_try_2) |
| 197 | bnv_err_2=`grep -v '^ *+' bnv_qt_test_2.out | grep -v "^bnv_qt_test.{$ac_ext}\$"`
|
| 198 | if test x"$bnv_err_2" != x; then |
| 199 | echo "$bnv_err_2" >&AC_FD_CC |
| 200 | echo "configure: could not compile:" >&AC_FD_CC |
| 201 | cat bnv_qt_test.$ac_ext >&AC_FD_CC |
| 202 | else |
| 203 | bnv_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o bnv_qt_main.o bnv_qt_main.$ac_ext >/dev/null 2>bnv_qt_test_3.out" |
| 204 | AC_TRY_EVAL(bnv_try_3) |
| 205 | bnv_err_3=`grep -v '^ *+' bnv_qt_test_3.out | grep -v "^bnv_qt_main.{$ac_ext}\$"`
|
| 206 | if test x"$bnv_err_3" != x; then |
| 207 | echo "$bnv_err_3" >&AC_FD_CC |
| 208 | echo "configure: could not compile:" >&AC_FD_CC |
| 209 | cat bnv_qt_main.$ac_ext >&AC_FD_CC |
| 210 | else |
| 211 | bnv_try_4="$CXX $QT_LIBS $LIBS -o bnv_qt_main bnv_qt_main.o moc_bnv_qt_test.o >/dev/null 2>bnv_qt_test_4.out" |
| 212 | AC_TRY_EVAL(bnv_try_4) |
| 213 | bnv_err_4=`grep -v '^ *+' bnv_qt_test_4.out` |
| 214 | if test x"$bnv_err_4" != x; then |
| 215 | echo "$bnv_err_4" >&AC_FD_CC |
| 216 | else |
| 217 | bnv_cv_qt_test_result="success" |
| 218 | fi |
| 219 | fi |
| 220 | fi |
| 221 | fi |
| 222 | ])dnl AC_CACHE_VAL bnv_cv_qt_test_result |
| 223 | AC_MSG_RESULT([$bnv_cv_qt_test_result]); |
| 224 | if test x"$bnv_cv_qt_test_result" = "xfailure"; then |
| 225 | # working Qt was not found |
| 226 | QT_CXXFLAGS= |
| 227 | QT_DIR= |
| 228 | QT_LIBS= |
| 229 | QT_UIC= |
| 230 | QT_MOC= |
| 231 | have_qt=no |
| 232 | AC_MSG_WARN([Failed to find matching components of a complete |
| 233 | Qt installation. Try using more options, |
| 234 | see ./configure --help.]) |
| 235 | fi |
| 236 | |
| 237 | rm -f bnv_qt_test.h moc_bnv_qt_test.$ac_ext moc_bnv_qt_test.o \ |
| 238 | bnv_qt_main.$ac_ext bnv_qt_main.o bnv_qt_main \ |
| 239 | bnv_qt_test_1.out bnv_qt_test_2.out bnv_qt_test_3.out bnv_qt_test_4.out |
| 240 | fi |
| 241 | ]) |
| 242 | |
| 243 | dnl Internal subroutine of BNV_HAVE_QT |
| 244 | dnl Set bnv_qt_dir bnv_qt_include_dir bnv_qt_bin_dir bnv_qt_lib_dir bnv_qt_lib |
| 245 | dnl Copyright 2001 Bastiaan N. Veelo <[email protected]> |
| 246 | AC_DEFUN([BNV_PATH_QT_DIRECT], |
| 247 | [ |
| 248 | ## Binary utilities ## |
| 249 | if test x"$with_Qt_bin_dir" != x; then |
| 250 | bnv_qt_bin_dir=$with_Qt_bin_dir |
| 251 | fi |
| 252 | ## Look for header files ## |
| 253 | if test x"$with_Qt_include_dir" != x; then |
| 254 | bnv_qt_include_dir="$with_Qt_include_dir" |
| 255 | else |
| 256 | # The following header file is expected to define QT_VERSION. |
| 257 | qt_direct_test_header=qglobal.h |
| 258 | # Look for the header file in a standard set of common directories. |
| 259 | bnv_include_path_list=" |
| 260 | /usr/include |
| 261 | `ls -dr /usr/include/qt* 2>/dev/null` |
| 262 | `ls -dr /usr/lib/qt*/include 2>/dev/null` |
| 263 | `ls -dr /usr/local/qt*/include 2>/dev/null` |
| 264 | `ls -dr /opt/qt*/include 2>/dev/null` |
| 265 | " |
| 266 | for bnv_dir in $bnv_include_path_list; do |
| 267 | if test -r "$bnv_dir/$qt_direct_test_header"; then |
| 268 | bnv_dirs="$bnv_dirs $bnv_dir" |
| 269 | fi |
| 270 | done |
| 271 | # Now look for the newest in this list |
| 272 | bnv_prev_ver=0 |
| 273 | for bnv_dir in $bnv_dirs; do |
| 274 | bnv_this_ver=`egrep -w '#define QT_VERSION' $bnv_dir/$qt_direct_test_header | sed s/'#define QT_VERSION'//` |
| 275 | if expr $bnv_this_ver '>' $bnv_prev_ver > /dev/null; then |
| 276 | bnv_qt_include_dir=$bnv_dir |
| 277 | bnv_prev_ver=$bnv_this_ver |
| 278 | fi |
| 279 | done |
| 280 | fi dnl Found header files. |
| 281 | |
| 282 | # Are these headers located in a traditional Trolltech installation? |
| 283 | # That would be $bnv_qt_include_dir stripped from its last element: |
| 284 | bnv_possible_qt_dir=`dirname $bnv_qt_include_dir` |
| 285 | if test -x $bnv_possible_qt_dir/bin/moc && |
| 286 | ls $bnv_possible_qt_dir/lib/libqt* > /dev/null; then |
| 287 | # Then the rest is a piece of cake |
| 288 | bnv_qt_dir=$bnv_possible_qt_dir |
| 289 | bnv_qt_bin_dir="$bnv_qt_dir/bin" |
| 290 | bnv_qt_lib_dir="$bnv_qt_dir/lib" |
| 291 | # Only look for lib if the user did not supply it already |
| 292 | if test x"$bnv_qt_lib" = xNO; then |
| 293 | bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p | |
| 294 | sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`" |
| 295 | fi |
| 296 | bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 297 | else |
| 298 | # There is no valid definition for $QTDIR as Trolltech likes to see it |
| 299 | bnv_qt_dir= |
| 300 | ## Look for Qt library ## |
| 301 | if test x"$with_Qt_lib_dir" != x; then |
| 302 | bnv_qt_lib_dir="$with_Qt_lib_dir" |
| 303 | # Only look for lib if the user did not supply it already |
| 304 | if test x"$bnv_qt_lib" = xNO; then |
| 305 | bnv_qt_lib="`ls $bnv_qt_lib_dir/libqt* | sed -n 1p | |
| 306 | sed s@$bnv_qt_lib_dir/lib@@ | [sed s@[.].*@@]`" |
| 307 | fi |
| 308 | bnv_qt_LIBS="-L$bnv_qt_lib_dir -l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 309 | else |
| 310 | # Normally, when there is no traditional Trolltech installation, |
| 311 | # the library is installed in a place where the linker finds it |
| 312 | # automatically. |
| 313 | # If the user did not define the library name, try with qt |
| 314 | if test x"$bnv_qt_lib" = xNO; then |
| 315 | bnv_qt_lib=qt |
| 316 | fi |
| 317 | qt_direct_test_header=qapplication.h |
| 318 | qt_direct_test_main=" |
| 319 | int argc; |
| 320 | char ** argv; |
| 321 | QApplication app(argc,argv); |
| 322 | " |
| 323 | # See if we find the library without any special options. |
| 324 | # Don't add top $LIBS permanently yet |
| 325 | bnv_save_LIBS="$LIBS" |
| 326 | LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 327 | bnv_qt_LIBS="$LIBS" |
| 328 | bnv_save_CXXFLAGS="$CXXFLAGS" |
| 329 | CXXFLAGS="-I$bnv_qt_include_dir" |
| 330 | AC_TRY_LINK([#include <$qt_direct_test_header>], |
| 331 | $qt_direct_test_main, |
| 332 | [ |
| 333 | # Success. |
| 334 | # We can link with no special library directory. |
| 335 | bnv_qt_lib_dir= |
| 336 | ], [ |
| 337 | # That did not work. Try the multi-threaded version |
| 338 | echo "Non-critical error, please neglect the above." >&AC_FD_CC |
| 339 | bnv_qt_lib=qt-mt |
| 340 | LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 341 | AC_TRY_LINK([#include <$qt_direct_test_header>], |
| 342 | $qt_direct_test_main, |
| 343 | [ |
| 344 | # Success. |
| 345 | # We can link with no special library directory. |
| 346 | bnv_qt_lib_dir= |
| 347 | ], [ |
| 348 | # That did not work. Try the OpenGL version |
| 349 | echo "Non-critical error, please neglect the above." >&AC_FD_CC |
| 350 | bnv_qt_lib=qt-gl |
| 351 | LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 352 | AC_TRY_LINK([#include <$qt_direct_test_header>], |
| 353 | $qt_direct_test_main, |
| 354 | [ |
| 355 | # Succes. |
| 356 | # We can link with no special library directory. |
| 357 | bnv_qt_lib_dir= |
| 358 | ], [ |
| 359 | # That did not work. Maybe a library version I don't know about? |
| 360 | echo "Non-critical error, please neglect the above." >&AC_FD_CC |
| 361 | # Look for some Qt lib in a standard set of common directories. |
| 362 | bnv_dir_list=" |
| 363 | `echo $bnv_qt_includes | sed ss/includess` |
| 364 | /lib |
| 365 | /usr/lib |
| 366 | /usr/local/lib |
| 367 | /opt/lib |
| 368 | `ls -dr /usr/lib/qt* 2>/dev/null` |
| 369 | `ls -dr /usr/local/qt* 2>/dev/null` |
| 370 | `ls -dr /opt/qt* 2>/dev/null` |
| 371 | " |
| 372 | for bnv_dir in $bnv_dir_list; do |
| 373 | if ls $bnv_dir/libqt*; then |
| 374 | # Gamble that it's the first one... |
| 375 | bnv_qt_lib="`ls $bnv_dir/libqt* | sed -n 1p | |
| 376 | sed s@$bnv_dir/lib@@ | sed s/[.].*//`" |
| 377 | bnv_qt_lib_dir="$bnv_dir" |
| 378 | break |
| 379 | fi |
| 380 | done |
| 381 | # Try with that one |
| 382 | LIBS="-l$bnv_qt_lib $X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS" |
| 383 | AC_TRY_LINK([#include <$qt_direct_test_header>], |
| 384 | $qt_direct_test_main, |
| 385 | [ |
| 386 | # Succes. |
| 387 | # We can link with no special library directory. |
| 388 | bnv_qt_lib_dir= |
| 389 | ], [ |
| 390 | # Leave bnv_qt_lib_dir defined |
| 391 | ]) |
| 392 | ]) |
| 393 | ]) |
| 394 | ]) |
| 395 | if test x"$bnv_qt_lib_dir" != x; then |
| 396 | bnv_qt_LIBS="-l$bnv_qt_lib_dir $LIBS" |
| 397 | else |
| 398 | bnv_qt_LIBS="$LIBS" |
| 399 | fi |
| 400 | LIBS="$bnv_save_LIBS" |
| 401 | CXXFLAGS="$bnv_save_CXXFLAGS" |
| 402 | fi dnl $with_Qt_lib_dir was not given |
| 403 | fi dnl Done setting up for non-traditional Trolltech installation |
| 404 | ]) |