Fix the compilation test for qscintilla2.
[autotroll.git] / build-aux / qscintilla2.m4
blobc67e99368a38724711e18865efed8ffdde3412e6
1 # M4 macros to build Qt apps that use qscintilla2 with the autotools
2 # (Autoconf/Automake).
3 # This file is part of AutoTroll.
4 # Copyright (C) 2006  Benoit Sigoure <tsuna@lrde.epita.fr>
6 # AutoTroll is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 # USA.
21 # This file relies on values (QT_*) defined by AutoTroll.
22 # Although it is not *required* to use AutoTroll along with this file, doing
23 # so provides better results since QScintilla is often located where Qt is.
25 # WITH_QSCINTILLA2()
26 # ------------------
27 # Check whether QsciScintilla2 is installed and usable.
28 # Defines $(QSCINTILLA2_LDFLAGS) which must be used before the Qt flags (if
29 # any).
30 AC_DEFUN([WITH_QSCINTILLA2],
31 [ AC_REQUIRE([AC_PROG_CXX])
32   AC_REQUIRE([AC_EXEEXT])
34   AC_ARG_WITH([qscintilla2],
35               [AS_HELP_STRING([--with-qscintilla2].
36                  [LDFLAGS to use for qscintilla2 @<:@-lqscintilla2 + Same as Qt@:>@])],
37               [QSCINTILLA2_LDFLAGS=$withval], [QSCINTILLA2_LDFLAGS='-lqscintilla2'])
39   # FIXME: Can we use a macro from autoconf to make something similar?
40   AC_CACHE_CHECK([for lib qscintilla2], [qt_cv_lqscintilla2],
41   [qt_cv_lqscintilla2=no
42   cat >conftest.cpp <<_ASEOF
43 #include <qsciscintilla.h>
44 #ifdef main  // Temporary work-around for Windows: Qt #defines main qMain
45 # undef main // but for some reason *I* can't link Qt apps because the linker
46 #endif       // fails to find it. To be FIXME'd.
47 struct Test: public QsciScintilla
51 int main ()
53   Test t;
55 _ASEOF
56   # Dirty hack :(
57   # Qt adds $(QT_DEFINES) in $QT_CXXFLAGS: we need to expand it here!
58   eval_qt_defines_sed="s/\$(QT_DEFINES)/$QT_DEFINES/"
59   MY_QT_CXXFLAGS=`echo "$QT_CXXFLAGS" | sed "$eval_qt_defines_sed"`
61   echo "$as_me:$LINENO: running: $CXX $QT_CPPFLAGS $AM_CPPFLAGS $CPPFLAGS \
62           $MY_QT_CXXFLAGS $AM_CXXFLAGS $CXXFLAGS \
63           conftest.cpp -o conftest$EXEEXT \
64           $QT_LDFLAGS $LDFLAGS \
65           $QSCINTILLA2_LDFLAGS $QT_LIBS $LIBS" \
66         >&AS_MESSAGE_LOG_FD
67   if $CXX $QT_CPPFLAGS $AM_CPPFLAGS $CPPFLAGS \
68           $MY_QT_CXXFLAGS $AM_CXXFLAGS $CXXFLAGS \
69           conftest.cpp -o conftest$EXEEXT \
70           $QT_LDFLAGS $LDFLAGS \
71           $QSCINTILLA2_LDFLAGS $QT_LIBS $LIBS \
72        >&AS_MESSAGE_LOG_FD 2>&1;
73   then
74     if test x"$QT_LIBS" != x; then
75       qt_cv_lqscintilla2="$QSCINTILLA2_LDFLAGS + Qt stuff"
76     else
77       qt_cv_lqscintilla2="$QSCINTILLA2_LDFLAGS"
78     fi
79   fi
80   if test x"$qt_cv_lqscintilla2" = xno; then
81     echo "$as_me:$LINENO: failed program was:" >&AS_MESSAGE_LOG_FD
82     sed 's/^/| /' conftest.cpp >&AS_MESSAGE_LOG_FD
83   fi
84   rm -f conftest.cpp conftest$EXEEXT
85   ])dnl End of AC_CACHE_CHECK for -lqscintilla2
87   if test x"$qt_cv_lqscintilla2" = xno; then
88     AC_MSG_ERROR([Cannot link with -lqscintilla2.])
89   fi
90   AC_SUBST([QSCINTILLA2_LDFLAGS])